1

please, i want find another way

example data

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

i see this result

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

delete from sales.copy 
where date = '2022-05-15' 
LIMIT 2;

but i want another way this part short

'date, sum(tomato), sum(phone)...'
7
  • 2
    There is no short way...and you are missing group by clause Commented May 20, 2022 at 8:35
  • I'd expect an error for your select. (Add a GROUP BY.) Commented May 20, 2022 at 8:37
  • LIMIT but no ORDER BY? Commented May 20, 2022 at 8:38
  • @jarlh LIMIT but no ORDER BY it will make sense if only one value match the criteria Commented May 20, 2022 at 9:31
  • @ErgestBasha, even less sense, since LIMIT isn't needed then. Commented May 20, 2022 at 9:33

1 Answer 1

1

So just group the result

select date, 
       sum(tomato), 
       sum(phone),
       sum(book), 
       sum(pen) 
from copy 
where date = '2022-05-15' 
GROUP BY date
Sign up to request clarification or add additional context in comments.

1 Comment

I think you are misunderstood the question ... but I want another way this part short 'date, sum(tomato), sum(phone)...'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.