mysql 如何用作子查询
mysql how use as subquery
示例数据
date
tomato
phone
book
pen
2022-05-15
2
2
3
1
2022-05-15
3
3
3
2
我想看
date
tomato
phone
book
pen
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 );
如果你找到其他方法
请尝试 post
示例数据
date | tomato | phone | book | pen |
---|---|---|---|---|
2022-05-15 | 2 | 2 | 3 | 1 |
2022-05-15 | 3 | 3 | 3 | 2 |
我想看
date | tomato | phone | book | pen |
---|---|---|---|---|
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 );
如果你找到其他方法 请尝试 post