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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 daily sales by each hour and grand total
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

usafelix
Posting Yak Master

Hong Kong
165 Posts

Posted - 08/21/2014 :  11:51:02  Show Profile  Reply with Quote
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

India
86 Posts

Posted - 01/09/2015 :  01:03:25  Show Profile  Reply with Quote
Group by Grouping Sets will give you the subtotal

Regards
Viggneshwar A
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000