Let’s say I have a table like this:
id | amount
-------------------------
1 | 10
1 | 10
2 | 20
2 | 10
3 | 20
3 | 10
3 | 10
4 | 10
Let’s say id 1 and 2 are special, I want to group them together and name it as special. Ids that are other than 1 and 2 should also not be grouped together. Lastly, I want to sum the amount. So, how to I get the result like this:
type | total_amount
-------------------------------
special | 50
3 | 40
4 | 10
3
Answers
You could use a
case when
to transformid
‘s values into the ones you are after, and then apply asum()
function to get the aggregate:please try this
You could also see separately each ID of special with the below code :