拜托,我想找到另一种方式
示例数据
| 日期 | 番茄 | 电话 | 书 | 笔 |
|---|---|---|---|---|
| 2022-05-15 | 2 | 2 | 3 | 1 |
| 2022-05-15 | 3 | 3 | 3 | 2 |
我看到了这个结果
| 日期 | 番茄 | 电话 | 书 | 笔 |
|---|---|---|---|---|
| 2022-05-15 | 5 | 5 | 6 | 3 |
我用这个
insert into sales.copy
select date,
sum(tomato),
sum(phone),
sum(book),
sum(pen)
from copy
where date = '2022-05-15';
delete from sales.copy
where date = '2022-05-15'
LIMIT 2;
但我想要另一种方式来简短地说明这部分
'date, sum(tomato), sum(phone)...'
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
所以只需对结果进行分组
select date, sum(tomato), sum(phone), sum(book), sum(pen) from copy where date = '2022-05-15' GROUP BY date