¿Cómo puedo obtener el recuento de pedidos realizados desde mi base de datos? [cerrado]

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

MySql ? Oracle ? what are the names of the columns ? what query did you try to run ? -

Try breaking this up into smaller issues and researching each one then if you stuck on any part come back here. We can't do it for you! -

i am using mysql with php and name of the columns are user_id,discount,service_tax,coupon_discount,total,date_Of_order. and need sum suggestion how to get the count of orders placed for individual day -

2 Respuestas

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í

violín Sql


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;

Respondido 04 Jul 12, 15:07

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:

2012-01-01 00:00:00

Entonces tu código debería ser como:

    FROM examp 
    GROUP BY DATEADD(DAY, DATEDIFF(DAY, 0, [date_of_order]),0)

Respondido 04 Jul 12, 10:07

A very nice point... but DATEADD is not supported by Mysql (i guess) but yes it works with SQLServer. - Ankit Suhail

Ah thanks for letting me know Ankit! Much appreciated. - TJH

as DATEADD is sqlserver function and supported in mysql than what is alternative for mysql - user1360564

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.