Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 HELP

Author  Topic 

rjdpa
Starting Member

2 Posts

Posted - 2009-12-03 : 11:25:16
I have over 1 million record... One of the fields has a datetime stamp.

I want to find out the maximum number of records within a one minute time frame. In other words, I want to find out the max number of records added within a minutes time.

What would be the best way to do this?

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-03 : 12:12:34
Try like this....

select max(no_of_occ),date_time from (
select
row_number() over( PARTITION by convert(varchar,date_time_column,101)+ ' '+cast(datepart(hh,date_time_column) as varchar(5))+':'+
cast(datepart(mi,date_time_column) as varchar(5)) order by convert(varchar,date_time_column,101)+ ' '+cast(datepart(hh,date_time_column) as varchar(5))+':'+
cast(datepart(mi,date_time_column) as varchar(5))) as no_of_occ,
convert(varchar,date_time_column,101)+ ' '+cast(datepart(hh,date_time_column) as varchar(5))+':'+
cast(datepart(mi,date_time_column) as varchar(5)) as date_time from con_tbl_user_log) a
group by date_time

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

rjdpa
Starting Member

2 Posts

Posted - 2009-12-03 : 12:36:58
worked! thank you very much!!!
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-03 : 12:51:55
quote:
Originally posted by rjdpa

worked! thank you very much!!!



Welcome

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-04 : 02:47:55
or
select max(no_of_acc) as no_of_acc,date_time_col from
(
select
dateadd(minute,datediff(minute,0,date_time_col),0) as date_time_col
,row_number() over (partition by dateadd(minute,datediff(minute,0,date_time_col),0) order by dateadd(minute,datediff(minute,0,date_time_col),0)) as no_of_acc
from con_tbl_user_log
) as t
group by date_time_col


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-04 : 02:54:27
quote:
Originally posted by senthil_nagore

Try like this....

select max(no_of_occ),date_time from (
select
row_number() over( PARTITION by convert(varchar,date_time_column,101)+ ' '+cast(datepart(hh,date_time_column) as varchar(5))+':'+
cast(datepart(mi,date_time_column) as varchar(5)) order by convert(varchar,date_time_column,101)+ ' '+cast(datepart(hh,date_time_column) as varchar(5))+':'+
cast(datepart(mi,date_time_column) as varchar(5))) as no_of_occ,
convert(varchar,date_time_column,101)+ ' '+cast(datepart(hh,date_time_column) as varchar(5))+':'+
cast(datepart(mi,date_time_column) as varchar(5)) as date_time from con_tbl_user_log) a
group by date_time

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/



Work on DATETIME not VARCHAR

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -