Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sql query with hour group by

Posted on 2011-02-28
2
Medium Priority
?
418 Views
Last Modified: 2012-06-27
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
Comment
Question by:romeiovasu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 35000125


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
 
LVL 4

Expert Comment

by:incerc
ID: 35000184
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question