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 > COUNTing 2 columns within one table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-21-04, 11:37
alexh alexh is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
COUNTing 2 columns within one table

I am trying to COUNT the bumber of entrants for 2 columns within the same table but the second COUNT has to have a WHERE clause.

SELECT COUNT(winID), count(isClaimed) FROM winners WHERE isClaimed =1

Here I am trying to return the entire number of records (winID - which is an auto-increment field) but only return the number of records from the column isClaimed wher the value = 1.

I am completely stumped. Anyone any ideas?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-21-04, 19:13
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Re: COUNTing 2 columns within one table

Quote:
Originally posted by alexh
I am trying to COUNT the bumber of entrants for 2 columns within the same table but the second COUNT has to have a WHERE clause.

SELECT COUNT(winID), count(isClaimed) FROM winners WHERE isClaimed =1

Here I am trying to return the entire number of records (winID - which is an auto-increment field) but only return the number of records from the column isClaimed wher the value = 1.

I am completely stumped. Anyone any ideas?

Thanks.
SELECT COUNT(winID) as winIDtotal,
sum(case when isClaimed=1 then 1 else 0 end) as isClaimedtotal
FROM winners;
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