I am preparing a chart which will display the number of orders placed for a particular day in the current month and year. I wanted the count of orders placed for each day. I am showing the count of orders on the y-axis and the day on the x-axis. In my database, there is table called "order" in which order data is placed: order date, user_id, order_price, etc. For example, if on 4 July, 10 orders are placed, on 5 july, 20 orders are placed, and so on.
How can I get the count of orders placed for day of the current month?
preguntado el 04 de julio de 12 a las 09:07
i didn't get what you mean correctly but here are two solutions for what i could collect from all the comments
- You need to count the number of orders placed in a particular day
if you want just the order on a particular date you can use this query
select count(*)as "Order Placed" from examp where date_of_order = '2012-01-15';
- you need a list of order placed (date wise)
select DATE_FORMAT(date_of_order,'%M %Y') as "Date",count(*) as "Order Placed" from examp group by date_of_order;
verlo funcionando aquí
Now if you want a list for a single month simply use a where clause.
select DATE_FORMAT(date_of_order,'%M %Y') as "DATE",count(*) as "Order Placed" from examp where month(date_of_order) = '2' group by date_of_order;
Just adding onto what Ankit has said..
When grouping by day you might have a problem if your date_of_order includes a timestamp:
e.g. 2012-01-01 12:37:01
If it does use DATEADD to round the time down to midnight so that you can group by day.
DATEADD(DAY, DATEDIFF(DAY, 0, [date_of_order]),0)
It will then look like:
Entonces tu código debería ser como:
SELECT date_of_order, COUNT(date_of_order) FROM examp GROUP BY DATEADD(DAY, DATEDIFF(DAY, 0, [date_of_order]),0)