0

我正在尝试根据cid同一张表在新表中获取成人和儿童的总和。

餐桌销售

+-----------+------------+---------------+
| cid       | adult      |  child        |
+-----------+------------+---------------+
|         1 |     20     |      20       | 
|         1 |     30     |      10       |
|         1 |    100     |      35       |
|         1 |     10     |      25       |
|         2 |     40     |      10       |
|         2 |     20     |      70       |
|         2 |     30     |      60       | 
+-----------+------------+---------------+

所需的输出:

+-----------+------------+---------------+
| cid       | adult      |  child        |
+-----------+------------+---------------+
|         1 |     160    |       90      | 
|         2 |      90    |      140      |
+-----------+------------+---------------+

请帮帮我

4

2 回答 2

3
SELECT cid, SUM(adult) AS adult, SUM(child) AS child 
FROM sales 
GROUP BY cid
于 2013-10-09T07:17:57.237 回答
1
SELECT cid,sum(adult) adult, sum(child) child FROM sales GROUP BY cid
于 2013-10-09T07:18:01.970 回答