SQL query for Calculating Total No. of Orders per Day?

前端 未结 5 1503
自闭症患者
自闭症患者 2021-01-13 01:13

Can anyone post a SQL query for Calculating Total No. of Orders per Day?

Here are the Columns along with their data in my Database.


order_id            


        
5条回答
  •  时光取名叫无心
    2021-01-13 01:23

    MySQL's date() function will return a DATEIME or TIMESTAMP value without any hour/minute/second info - which means you reduce the accuracy to the day of the value.

    So all you need to do is group by that and then add your aggregate functions to the right columns.

    SELECT date(order_placed_date)
         , COUNT(id) AS num_orders
         , SUM(order_total) AS daily_total
      FROM [Table]
     GROUP BY date(order_placed_date)
    

提交回复
热议问题