A
A
albertalexandrov2018-07-31 16:35:52
SQL
albertalexandrov, 2018-07-31 16:35:52

How to choose the date of maximum sales?

Hello!
The task is to find the date of maximum sales. Table:
OGkv3ohzHt0.jpg
Now I grouped the sales (query in the screenshot) by dates and got:
8DZUVHMTxZM.jpg
Finally, I should get the date 2017-01-02, when the sales are maximum and amount to 1105.
How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton fon Faust, 2018-07-31
@albertalexandrov

SELECT `date`, SUM( total) AS bablo
FROM  `sale` 
GROUP BY `date`
ORDER BY bablo DESC 
LIMIT 1

R
Ruslan., 2018-07-31
@LaRN

You can try like this:

select date, sum(total) as sum 
  from sale 
 group by date
having sum(total) >= all (select sum(total)
                            from sale 
                           group by date)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question