샘플 예제는 이렇구요.
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 );
© 2023 OneMinuteCode. All rights reserved.