+ 1

Help needed with SQL command GROUP BY

Hello community, I am currently trying to get information about orders placed per day by my customers. The command I am running is: SELECT COUNT(orderDate), clientName, FROM table GROUP BY orderDate The problem I have is that if 2 or more clients placed an order in the same day, the values I receive after running the command above is the total quantity of orders for the day but only 1 value for client. Is there a way for me to see the orders each client has placed each day? The only way I can do it is if I use the WHERE command and create different queries for each client, but since I have more than 100 of them that will be crazy amount of work. Your help will be much appreciated.

17th Oct 2020, 4:23 PM
Plamen Todorov
Plamen Todorov - avatar
2 Réponses
+ 2
Not sure this will work, but maybe try GROUP BY orderDate, clientName?
17th Oct 2020, 5:02 PM
Ipang
+ 1
It's hard to answer without a scheme of the DB. If you have only one table: SELECT orderDate, clientName, COUNT(orderDate) AS nrOfOrders FROM orders WHERE orderDate IS NOT NULL GROUP BY orderDate, clientName ORDER BY orderDate DESC, clientName ASC;
18th Oct 2020, 12:36 AM
Vasile Eftodii
Vasile Eftodii - avatar