Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k points)

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

Sales (saleID INT, amount INT, created DATETIME)

Update I am using SQL Server 2005

1 Answer

0 votes
by (40.7k points)

If you are using the SQL Server, dateadd(DAY,0, datediff(day,0, created)) then it will return the created day.

For example, if the sale is created on '2009-11-02 06:12:55.000', dateadd(DAY,0, datediff(day,0, created)) then it'll return '2009-11-02 00:00:00.000'

Try this:

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))

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...