TechHero
TechHero

Reputation: 21

Add values in one column based on value of another SQL

I have a data set here:

YOA    Count
2014    43
2014    2
2014    17
2016    47
2015    191
2017    185
2016    26
2014    119
2016    33

What I'd like to do is write a SQL query that displays:

2017 - all counts for 2017
2016 - all counts for 2017
2015 - all counts for 2017
2014 - all counts for 2017

Upvotes: 0

Views: 32

Answers (2)

apomene
apomene

Reputation: 14389

Use SUM with GROUP BY:

SELECT YOA,SUM([Count]) FROM myTable GROUP BY YOA

Upvotes: 0

Rahul Jain
Rahul Jain

Reputation: 1399

Try this:

SELECT YOA, SUM(count) total
FROM tableName
GROUP BY YOA

Upvotes: 1

Related Questions