Grouping in a query

Mick_Hart

New Member
Joined
Nov 19, 2004
Messages
32
Okay, so i have a list times throughout the day. These times range from midnight to midnight, occuring in minute intervals.

I need to build a query, so that i change -

Time | Ammount
00:30 | 1
00:31 | 6
08:41 | 19
08:59 | 1
15:00 | 6
15:31 | 7

Into this

Time | Ammount
00:30 - 00:59 | 7
08:30 - 08:59 | 21
15:00 - 15:29 | 6
15:30 - 15:59 | 7


I havent got a clue as to where to start with this, so any help would be greatly appreciated :)
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Enter this as SQL:

SELECT IIf(Right([time],2)>=30,Left([time],2) & ":30 - " & Left([time],2) & ":59",Left([time],2) & ":00 - " & Left([time],2) & ":29") AS TimeGroup, Sum(tblTimes.Amount) AS SumOfAmount
FROM tblTimes
GROUP BY IIf(Right([time],2)>=30,Left([time],2) & ":30 - " & Left([time],2) & ":59",Left([time],2) & ":00 - " & Left([time],2) & ":29");

I used tblTimes as the table name, adjust to suit.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,248
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top