SQL query to group by day

后端 未结 8 2024
感动是毒
感动是毒 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:48

    For oracle you can

    group by trunc(created);
    

    as this truncates the created datetime to the previous midnight.

    Another option is to

    group by to_char(created, 'DD.MM.YYYY');
    

    which achieves the same result, but may be slower as it requires a type conversion.

提交回复
热议问题