Skip to content
Advertisement

SQL_Case and When

I have a data set where I need to calculate minimum amount due. I have used the below code

The intention is to bring minimum amount due as Rs. 500 if the net sales is less than Rs. 500, if the net sales is more than Rs. 500 then I need to calculate 10% of Net sales.

Sample data for reference

For some reason I’m unable to get the result. Help would be much appreciated!

Advertisement

Answer

Compute the aliases in a CTE first, then subquery that to get the result you want:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement