简体   繁体   中英

mysql how use as subquery

example data

date tomato phone book pen
2022-05-15 2 2 3 1
2022-05-15 3 3 3 2

i want see

date tomato phone book pen
2022-05-15 5 5 6 3

i use this

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' );

doesn't works part

delete from sales.copy
where date = '2022-05-15' and tomato < ( select max(tomato) from sales.copy where date = '2022-05-15' );

i found way! thanks everybody!

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 );

if you find another way please, try post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM