troubleshooting Question

Group data into 4 hour interval and dont sum or avg a column - sql server script

Avatar of deanmachine333
deanmachine333Flag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL ServerSQL
6 Comments1 Solution104 ViewsLast Modified:
Hello, I have this query that has data for every minute which I have attached some data of the table.

I want to group this into 4 hours starting from 00:00, but I don't want to sum or average the value in the column [Last] I just want to return that value in the [Last] column as it is at that specific grouped hour.

SELECT b.[timestamp], b.[id], b.[Date], b.[HourMin], b.[Min], b.[Last]
FROM [vw_BassLineDataTimestamp] b

So should return this instead

timestamp                             id                                                      Date             HourMin     Min      Last
2017-11-20T08:00:48.467      BTC-LTC_2017-11-20_08:00      2017-11-20      08:00          0              0.00890995
2017-11-20T04:00:50.583      BTC-LTC_2017-11-20_04:00      2017-11-20      04:00          0              0.009015
2017-11-20T00:00:51.573      BTC-LTC_2017-11-20_00:00      2017-11-20      00:00          0              0.0089

Thanks in advance.

Also if possible could I amend the hour interval so instead of 4 hours (240 min) to any say like 5.71667 hours (343min) or any interval would be great.

Kind regards
LTC1minData.xlsx
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros