Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Query SQL per raggruppare per giorno

se stai usando SQL Server,

dateadd(DAY,0, datediff(day,0, created)) restituirà il giorno creato

ad esempio, se la vendita è stata creata il '2009-11-02 06:12:55.000',dateadd(DAY,0, datediff(day,0, created)) ritorno '2009-11-02 00:00:00.000'

select sum(amount) as total, dateadd(DAY,0, datediff(day,0, created)) as created
from sales
group by dateadd(DAY,0, datediff(day,0, created))