If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Summing a count field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-22-08, 07:53
gugs gugs is offline
Registered User
 
Join Date: Sep 2008
Posts: 6
Summing a count field

I am running the following sql query:

db2 "select (integer(length(message))), count(*) from db2.logging where date(datestamp) = '2008-09-01' AND (integer(length(message))) BETWEEN 1000 AND 5000 GROUP BY length(message)"

I am getting a count of the messages as expected e.g.:

1 2
--------- -----------
1000 5
1005 2
1110 50

However, what I want is the sum of count field (2) i.e. in the above example 57 - is there any way of doing this?
Reply With Quote
  #2 (permalink)  
Old 09-22-08, 08:12
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Use a CTE (Common table expression):

with t1 (msg_len,quantity) (
select (integer(length(message))), count(*) from db2.logging where date(datestamp) = '2008-09-01' AND (integer(length(message))) BETWEEN 1000 AND 5000 GROUP BY length(message)
) select sum(quantity) from t1

Andy
Reply With Quote
  #3 (permalink)  
Old 09-22-08, 08:35
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
just omit the group by:

db2 "count(*) from db2.logging where date(datestamp) = '2008-09-01' AND (integer(length(message))) BETWEEN 1000 AND 5000"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On