Skip to content
Advertisement

Calculate a column based on if else condition

I am trying to calculate the discounted cost for an account based on its product codes where different codes get different discounts. I am struggling to find a way where I can modify the query so that it will give me the right results in one query rather than me running the same query multiple times and changing the discount and product code.

As an example if the code is AmazonEC2 then apply 5% to the cost if the code is AmazonS3 then apply 3% to the cost, else apply 1% to the rest.

Advertisement

Answer

If you want the information per account or per account per day, then I don’t think you want line_item_product_code in the GROUP BY.

In that case, you want conditional aggregation:

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