Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql help, please


sql help, please

Author
Message
rightontarget
rightontarget
SSC-Enthusiastic
SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)

Group: General Forum Members
Points: 135 Visits: 465
Hi all,
Wonder if I am missing something obvious, but I can't seem to get it.
I need to come up with a query that returns start_time, end_time, count for every 5 min interval.
Here is the sample data:

create table A (process_date datetime);
insert into A (process_date)
values
('2014-04-24 00:00:00.000'),
('2014-04-24 00:01:05.000'),
('2014-04-24 00:01:07.000'),
('2014-04-24 00:02:09.000'),
('2014-04-24 00:02:10.000'),
('2014-04-24 00:03:11.000'),
('2014-04-24 00:03:13.000'),
('2014-04-24 00:04:14.000'),
('2014-04-24 00:04:14.000'),
('2014-04-24 00:05:14.000'),
('2014-04-24 00:05:14.000'),
('2014-04-24 00:06:15.000'),
('2014-04-24 00:06:15.000'),
('2014-04-24 00:07:16.000'),
('2014-04-24 00:08:16.000'),
('2014-04-24 00:08:16.000'),
('2014-04-24 00:09:16.000'),
('2014-04-24 00:09:16.000'),
('2014-04-24 00:09:16.000'),
('2014-04-24 00:10:16.000'),
('2014-04-24 00:10:16.000');
select * from A;



So, in this case I'd like to see:

start_date, end_date, count(*)
'2014-04-24 00:00:00.000', '2014-04-24 00:05:14.000', 11
'2014-04-24 00:05:14.000', '2014-04-24 00:10:16.000', 10



Thanks,
gbritton1
gbritton1
Old Hand
Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)

Group: General Forum Members
Points: 369 Visits: 840
Why are the intervals in the desired output > 5 minutes?
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16568 Visits: 17016
I agree your desired output doesn't match your description because you have intervals outside of the 5 minutes.

Something like this get you started?


select MIN(process_date) as StartDate, MAX(process_date) as EndDate, COUNT(*)
from A
group by DATEPART(minute, process_date) / 5



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
rightontarget
rightontarget
SSC-Enthusiastic
SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)

Group: General Forum Members
Points: 135 Visits: 465
Thanks for reply. Your query helped a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search