[Solved] How Should I do to limit the value calculated by AVG or SUM [closed]


You can use least():

   least(sum(case when type="A" then cost else -cost end) * 0.08, 300) as AMY 

If the sum() exceeds 300, then the return value is 300. You can use greatest() if you want to impose a minimum. So, this would ensure that the value is between -300 and 300:

   greatest(least(sum(case when type="A" then cost else -cost end) * 0.08, 300), -300) as AMY 

1

solved How Should I do to limit the value calculated by AVG or SUM [closed]