lookbackatit_
lookbackatit_

Reputation: 37

How do I get the sum of each line depending on the team name?

I have a table called data:

enter image description here

And I would like to get the sum of each row as column name, like this: enter image description here

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

Answers (1)

Yogesh Sharma
Yogesh Sharma

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

Related Questions