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 

http://sqlfiddle.com/#!2/2bfb1/2


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -