Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Query Problem
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00640926
Message ID:
00640999
Views:
9
This message has been marked as the solution to the initial question of the thread.
Something like
SELECT CAST(dt.date1 + dt.min1 AS datetime) as Begins, 
	DATEADD( mi,10, CAST(dt.date1 + dt.min1 AS datetime)) AS Ends,
	COUNT(*) as total FROM 
	 (SELECT proc_dt, 
	RIGHT(CONVERT( CHAR(8), proc_dt,108),5) as Time1, 
	CONVERT( CHAR(14), proc_dt,120) date1,
	CASE 
	WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '50:00' THEN '50:00'
	WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '40:00' THEN '40:00'
	WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '30:00' THEN '30:00'
	WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '20:00' THEN '20:00'
	WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '10:00' THEN '10:00'
	WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '00:00' THEN '00:00'
	ELSE '??:??' END min1
FROM orders
WHERE proc_dt IS NOT NULL) dt
GROUP BY CAST(dt.date1 + dt.min1 AS datetime), DATEADD( mi,10, 
	CAST(dt.date1 + dt.min1 AS datetime)) 
ORDER BY 1

-- or combaining things together
SELECT dt.IntervalBegins, 
	DATEADD( mi,10, IntervalBegins) AS IntervalEnds,
	COUNT(*) as total FROM 
	 (SELECT  
	   CAST( CONVERT( CHAR(14), proc_dt,120) + 
		CASE 
		WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '50:00' THEN '50:00'
		WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '40:00' THEN '40:00'
		WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '30:00' THEN '30:00'
		WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '20:00' THEN '20:00'
		WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '10:00' THEN '10:00'
		WHEN RIGHT(CONVERT( CHAR(8), proc_dt,108),5) > '00:00' THEN '00:00'
		ELSE '??:??' END AS datetime ) AS IntervalBegins
FROM orders
WHERE proc_dt IS NOT NULL) dt
GROUP BY IntervalBegins, DATEADD( mi,10, IntervalBegins)
ORDER BY 1
You convert datime field proc_dt into beginnig of the interval and than group by it.


>Im havnig problems getting this query to work right. What I have is a table of logins to a website. In the table containes the dattime of the loging along with other info. I need a query containing the number of logins within every 10 minute time interval.
>
>For example
>
>1/1/02 12:00 pm to 1/1/02 12:10 pm - 10 logins
>1/1/02 12:10 pm to 1/1/02 12:20 pm - 15 logins
>1/1/02 12:20 pm to 1/1/02 12:30 pm - 6 logins
>...
>
>I hope this makes sence. Any ideas?
>
>Eric Stephani
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform