[英]mysql how use as subquery
示例數據
日期 | 番茄 | 電話 | 書 | 筆 |
---|---|---|---|---|
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';
GROUP BY date
delete from sales.copy
where date = '2022-05-15' and tomato < ( select max(tomato) from sales.copy where date = '2022-05-15' );
不起作用
delete from sales.copy
where date = '2022-05-15' and tomato < ( select max(tomato) from sales.copy where date = '2022-05-15' );
我找到了方法! 謝謝大家!
delete from sales.copy WHERE date = '2022-05-15' AND tomato < ( select MAX(tomato) FROM (SELECT tomato from sales.copy where date = '2022-05-15') AS temp );
如果您找到其他方法,請嘗試發布
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.