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 > MySQL > Problem with COUNT and HAVING

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-04, 10:49
rickd rickd is offline
Registered User
 
Join Date: Jun 2004
Location: Florida
Posts: 7
Problem with COUNT and HAVING

The following SQL returns 50 rows:

select cpr2.rxclaimnbr from claimspaidreversed as cpr1 join claimspaidreversed as cpr2 on (cpr1.rxclaimnbr=cpr2.rxclaimnbr) where cpr1.datesbm='2004-06-04' group by cpr2.rxclaimnbr having mod(count(cpr2.claimsts),2)=0

So I threw a count() around cpr2.rxclaimnbr hoping to get back one row containing the number 50.

Instead I get back 50 rows, with what looks like the number of items in each group.

How do I get back the number of rows?
Reply With Quote
  #2 (permalink)  
Old 06-10-04, 14:21
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
I think this is all you need:

Code:
select cpr2.rxclaimnbr, count(*)
from claimspaidreversed as cpr1 
join claimspaidreversed as cpr2 
on (cpr1.rxclaimnbr=cpr2.rxclaimnbr) 
where cpr1.datesbm='2004-06-04' 
group by cpr2.rxclaimnbr 
having mod(count(cpr2.claimsts),2)=0
Reply With Quote
  #3 (permalink)  
Old 06-10-04, 15:25
rickd rickd is offline
Registered User
 
Join Date: Jun 2004
Location: Florida
Posts: 7
This generates 50 rows, with the first column the claim number, and the second the number of rows in each group.
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