Reputation: 37
I have a table called data:
And I would like to get the sum of each row as column name, like this:
What is the correct SQL statement I need? I've been trying with CASE or IF but I just don't get the right answer.
Upvotes: 0
Views: 29
Reputation: 50163
You need aggregation :
select
sum(case when team = 'team business' then total_points else 0 end) as total_business,
sum(case when team = 'team tech' then total_points else 0 end) as total_tech
from
data d;
Upvotes: 1