select - SQL - set min or max value in calculation -
my database items contains specifications (id, name, length, height, weight, quantity, etc).
i want
select id, name, length*3 + height*5 'newvar' items order newvar desc
however, in order formulas work in calculation of newvar
, if 'length' smaller 10, want reflected 10 in calculation. same goes 'height': if greater 10, need reflected 10 in calculation.
how can achieve this?
you can accomplish couple of case
conditions return 10
if length
or height
< 10
or > 10
respectively.
select id, name, ((case when length < 10 10 else length end) * 3 + (case when height > 10 10 else height end) * 5) newvar items order newvar desc
Comments
Post a Comment