Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping by time intervals

Status
Not open for further replies.

kaledev

Programmer
Aug 3, 2007
6
0
0
US
I am attempting to group records by 12 minute intervals. I.E. 12:00pm-12:12pm, 12:13pm-12:25pm, etc. I am currently grouping in 10 minute intervals...although the current method won't exactly work for 12. Can anyone give some advice on this? See the SQL below:

Code:
SELECT TIMESTAMP(LEFT(char(nvs.TXN_DT_TM),13) || '.' || RIGHT(LEFT(char(nvs.TXN_DT_TM),15),1) || '0.00.000000') as YYYY_MM_DD_HH_10MM,
	count(DISTINCT nvs.UZRL) AS "Unique Users",
	cast(count(DISTINCT nvs.UZRL) as float)/6 AS "Labor Hours"
FROM db.table nvs
WHERE nvs.TXN_DT_TM >= '2011-01-01-00.00.00' and date(nvs.TXN_DT_TM) >= (current date)
AND (nvs.MVKD = 'RDSC' AND nvs.PFHS = 'Y')
GROUP BY TIMESTAMP(LEFT(char(nvs.TXN_DT_TM),13) || '.' || RIGHT(LEFT(char(nvs.TXN_DT_TM),15),1) || '0.00.000000')
 
Try this:
Code:
SELECT TIMESTAMP(LEFT(CHAR(CURRENT_TIMESTAMP),13) || '.' ||
LEFT(CHAR(INTEGER(MINUTE(CURRENT_TIMESTAMP)/12)+1),1)
|| '0.00.000000'), CURRENT_TIMESTAMP
FROM SYSIBM.SYSDUMMY1

I've added the timestamp at the end so you can see what's doing. It breaks the minutes into 12 minute chunks, which looks to me as it will work but I haven't fully tested it.

Let me know if it fits.

Marc
 
Thinking about it, you will need to remove the +1 on the second line of code as that will give you a timestamp of 60 during the last 12 minute period which is invalid.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top