Reputation: 902
I have a tables and I want the sum of the column if the ID is repeated
CountValues ID
____________________
1 23
4 23
2 12
2 23
If ID is repeated then CountValues must be sum of ID itself like below
CountValues ID
____________________
7 23
2 12
What should be the sql query?
Upvotes: 0
Views: 350
Reputation: 7171
Try this query
select sum(CountValues) as CountValues, ID
from TABLE
group by ID
Upvotes: 1
Reputation: 44581
You can use sum
aggregate function together with the group by
clause:
select sum(CountValues) as CountValues, ID
from tbl
group by ID
Upvotes: 1
Reputation: 11556
Use the aggregate function SUM
with GROUP BY
.
Query
select SUM(CountValues) as CountValues, ID
from your_table_name
group by ID;
Upvotes: 0