Reputation: 47
I'm trying to get the sum of adult and child in new table based on cid
from the same table.
table sales
+-----------+------------+---------------+
| cid | adult | child |
+-----------+------------+---------------+
| 1 | 20 | 20 |
| 1 | 30 | 10 |
| 1 | 100 | 35 |
| 1 | 10 | 25 |
| 2 | 40 | 10 |
| 2 | 20 | 70 |
| 2 | 30 | 60 |
+-----------+------------+---------------+
desired output:
+-----------+------------+---------------+
| cid | adult | child |
+-----------+------------+---------------+
| 1 | 160 | 90 |
| 2 | 90 | 140 |
+-----------+------------+---------------+
plz help me
Upvotes: 0
Views: 38
Reputation: 5607
SELECT cid,sum(adult) adult, sum(child) child FROM sales GROUP BY cid
Upvotes: 1
Reputation: 46900
SELECT cid, SUM(adult) AS adult, SUM(child) AS child
FROM sales
GROUP BY cid
Upvotes: 3