I'm trying to count occurrences of values in a specific column.
cus_id      prod_id     income 
100           10          90
100           10          80
100           20         110
122           20           9
122           30          10
When doing the query, I would like to receive something like this:
cus_id     count(prod_id = 10)    (prod_id = 20)    (prod_id = 30)     sum(income)
100                2                     1                 0                280
122                0                     1                 1                 19   
At the moment my initial approach is this:
select cus_id, prod_id, count(prod_id), sum(income) from t group by 1,2
Any insights would be highly appreciated. Thanks in advance!
 
    