Here is an example of my table.
┌────────┬────────┬───────┐
│ UserId │ Status │ Value │
├────────┼────────┼───────┤
│ 1 │ 1 │ 10 │
│ 1 │ 0 │ 5 │
│ 2 │ 0 │ 8 │
│ 2 │ 1 │ 15 │
│ 1 │ 1 │ 10 │
│ 1 │ 0 │ 5 │
└────────┴────────┴───────┘
I need to GROUP BY rows with UserId then COUNT total rows in the group, to this point I have no problem but I also want to SUM(Value) according Status Column. Like COUNT my sql give me total sum of group rows but I need result like below :-)
┌────────┬──────────────────────┬─────────────────────┐
│ UserId │ SUM(Value) Status=1 │ SUM(Value) Status=0 │
├────────┼──────────────────────┼─────────────────────┤
│ 1 │ 20 │ 10 │
│ 2 │ 15 │ 8 │
└────────┴──────────────────────┴─────────────────────┘
NOTE: This type of query called Conditional Aggregation you may search for more about this.