• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

sql query with hour group by

hi all,
i am trying to write a query where i am trying to get a result like this.
locationid storeid date              time totalin totalout
1234         abc      12/01/2011   11     5         2
1234         abc      12/01/2011   16     4         1

i am attaching my data how it is store in.

can someone help me out.


 arjaytelecom20101116-1-.csv
0
romeiovasu
Asked:
romeiovasu
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:


select locationId, storeid, date , datepart (hour ,CONVERT(datetime, date+' time' ) ), sum(in)  , sum( out )
from tableName
group by locationId, storeid, date , datepart (hour ,CONVERT(datetime, date+' time' ) )
0
 
incercCommented:
Hi,

In SQL Server you can use Datepart(<part>, <date>) to obtain the hour part from a time field :
http://msdn.microsoft.com/en-us/library/ms174420.aspx

Your query should be something like :

SELECT locationid, storeid, date, datepart(hh, time), sum(totalin), sum(totalout)
FROM mytable
GROUP BY  date, datepart(hh, time), locationid, storeid


0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now