We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2017-11-20
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

Open in new window

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
Watch Question
Database Expert
Awarded 2016
Top Expert 2016
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE