Webmaster Help
|
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jan 05, 2009, 08:32:32 PM

Login with username, password and session length

There is no security on this earth, there is only opportunity.


- General Douglas MacArthur

Welcome Guest - Register or Login Now to remove these advertisments


Registration is completely free and only takes a few minutes to signup !

|-   Entrepreneur Forum > Webmasters - Discuss Making Money Online > Website Design and Maintenance > Database
+   How can I use count() multiple times in one query ?
0 Members and 1 Guest are viewing this topic.
Pages: [1] Reply to Thread
Author Topic: How can I use count() multiple times in one query ?  (Read 257 times)
OfflineCrackerJack
New Member
CrackerJack is on a distinguished road
Joined: Jul 2008
Posts: 41


Avatar of CrackerJack

View CrackerJack\s ProfileWWW
Gender: MaleAries United States
notepad Jul 23, 2008, 01:20:37 PM #1
I need to write a sql statement for mysql that counts the number of records that contain a specific value and null using one query instead of lots of separate queries.

I tried this query but it's not working

Code:
SELECT site_stat,
COUNT(site_stat='Approved') AS "approved",
COUNT(site_stat='NULL') AS "not approved"
FROM sites
GROUP BY site_stat 

How can I do this? Is it even possible ?


OfflineAceCoder
Junior Member
AceCoder is on a distinguished road
Joined: Oct 2007
Posts: 64



View AceCoder\s ProfileWWW
Germany
notepad Jul 27, 2008, 09:13:41 PM #2
You'll have to use a JOIN statement on that query if you want to do multiple count statements.

Latest Blog Post : PHP - Pass by Reference or Pass by Value

OfflineCrackerJack
New Member
CrackerJack is on a distinguished road
Joined: Jul 2008
Posts: 41


Avatar of CrackerJack

View CrackerJack\s ProfileWWW
Gender: MaleAries United States
notepad Dec 01, 2008, 02:13:34 PM #3
still haven't figured out how to do the JOIN but I just did it using two seperate queries.

Pages: [1] Reply to Thread


Code4Gold Affiliate Entrepreneur Moneymaker Forum © 2006-2008 Resdaz Media LLC - All Rights Reserved

Forum Software Powered by SMF - © 2001-2008, Lewis Media. All Rights Reserved.