SQL query to group by day

后端 未结 8 1988
感动是毒
感动是毒 2020-12-04 09:21

I want to list all sales, and group the sum by day.

Sales (saleID INT, amount INT, created DATETIME)

NOTE: I am using SQL Server 2005.

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 09:36

    actually this depends on what DBMS you are using but in regular SQL convert(varchar,DateColumn,101) will change the DATETIME format to date (one day)

    so:

    SELECT 
        sum(amount) 
    FROM 
        sales 
    GROUP BY 
        convert(varchar,created,101)
    

    the magix number 101 is what date format it is converted to

提交回复
热议问题