Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 daily sales by each hour and grand total

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2014-08-21 : 11:51:02
I'm trying to get revenue by hour in one table. I would like to get the following columns and sku is contain of '%baby or oil%' and the hour from morning at 8:00 am to 22:00 pm and time range in below: please help to write a sql query .

08:00 - 09:00
09:00 - 10:00
10:00 - 11:00
11:00 - 12:00
12:00 - 13:00
21:00 - 22:00

StoreID, TransactionDate, TransactionHour, sku, TotalSales
A shop 20140821 13:00-14:00 oil $100
A shop 20140821 13:00-14:00 baby $100
Total $200

B shop 20140821 15:00-16:00 kid baby $250
B shop 20140821 21:00-22:00 skin oil $150
Total $400

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-09 : 01:03:25
Group by Grouping Sets will give you the subtotal

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -