Hello,

The following query should select the day, the number of sales for that day and the departments:

SELECT DATE(s.transaction_date) as day, d.name as department, COUNT(s.id) as sale_count FROM sale s JOIN department d on d.id = s.department_id group by d.name, s.transaction_date 

But he somehow incorrectly counts COUNT. Tell me, what's the problem?

enter image description here

  • как-то неправильно считает COUNT - doesn’t it seem to you, sir, that under this formulation it’s not clear what it means? - Alexey Shimansky
  • I apologize. Here is the result: imgur.com/a/NWi0h - nikita100k
  • And where does count() it all right? You have a transaction date with time, since you take date() from above and in group by why you don’t use date and the grouping is accurate to a second, i.e. essentially no grouping - Mike
  • Thank you very much. Now add the answer with the correct code. - nikita100k

1 answer 1

Thanks to Mike's help, the correct answer was found:

 SELECT DATE(s.transaction_date) as day, d.name as department, COUNT(s.id) as sale_count FROM sale s JOIN department d on d.id = s.department_id group by d.name, DATE(s.transaction_date) ORDER BY DATE(s.transaction_date) ASC