dbTalk Databases Forums  

count(*) by hour

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss count(*) by hour in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hayko98
 
Posts: n/a

Default count(*) by hour - 02-25-2010 , 02:51 PM






Hi all
I have this query
SELECT COUNT(*)
FROM Pro
WHERE D_TIME BETWEEN '2010-02-14 00:00:00.000' AND '2010-02-20
23:59:59.000'
AND convert(varchar(30),D_TIME,114) BETWEEN '00:00:00.000' AND
'00:59:59.000'
which gives me the total count for 00:00-00:59 from 02-14-10 thru
02-20-10.
i need to get for all 24 hours in 1 statment.

Time Total
00:00-00:59
01:00-01:59
02:00-02:59
......
23:00-23:59

Thank you

Reply With Quote
  #2  
Old   
David Solimano
 
Posts: n/a

Default Re: count(*) by hour - 02-25-2010 , 07:27 PM






On Thu, 25 Feb 2010 12:51:11 -0800 (PST), hayko98
<vardan.hakopian (AT) gmail (DOT) com> wrote:

Quote:
Hi all
I have this query
SELECT COUNT(*)
FROM Pro
WHERE D_TIME BETWEEN '2010-02-14 00:00:00.000' AND '2010-02-20
23:59:59.000'
AND convert(varchar(30),D_TIME,114) BETWEEN '00:00:00.000' AND
'00:59:59.000'
which gives me the total count for 00:00-00:59 from 02-14-10 thru
02-20-10.
i need to get for all 24 hours in 1 statment.

Time Total
00:00-00:59
01:00-01:59
02:00-02:59
.....
23:00-23:59

Thank you
Give this a try:

SELECT DATEPART(hh, D_TIME), COUNT(*)
FROM Pro
WHERE D_TIME BETWEEN '2010-02-14 00:00:00.000' AND '2010-02-20
23:59:59.000'
GROUP BY DATEPART(hh, D_TIME)

This should give you one row for each hour in your query.

--
David

Reply With Quote
  #3  
Old   
hayko98
 
Posts: n/a

Default Re: count(*) by hour - 02-26-2010 , 05:19 PM



On Feb 25, 5:27*pm, David Solimano <da... (AT) solimano (DOT) org> wrote:
Quote:
On Thu, 25 Feb 2010 12:51:11 -0800 (PST), hayko98





vardan.hakop... (AT) gmail (DOT) com> wrote:
Hi all
I have this query
SELECT COUNT(*)
FROM * Pro
WHERE * * *D_TIME BETWEEN '2010-02-14 00:00:00.000' AND '2010-02-20
23:59:59.000'
* * * AND convert(varchar(30),D_TIME,114) BETWEEN '00:00:00.000' AND
'00:59:59.000'
which gives me the total count for 00:00-00:59 from 02-14-10 thru
02-20-10.
i need to get for all *24 hours in 1 statment.

Time * * * * * * * Total
00:00-00:59
01:00-01:59
02:00-02:59
.....
23:00-23:59

Thank you

Give this a try:

SELECT DATEPART(hh, D_TIME), COUNT(*)
FROM * Pro
WHERE * * *D_TIME BETWEEN '2010-02-14 00:00:00.000' AND '2010-02-20
23:59:59.000'
GROUP BY DATEPART(hh, D_TIME)

This should give you one row for each hour in your query.

--
David- Hide quoted text -

- Show quoted text -
Thank you.
It worked

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.