MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Beauford Date:September 28 2007 5:31pm
Subject:RE: Count syntax
View as plain text  
Thanks - it works, but what does the 1 and 0 do in this -
SUM(IF(supportertype = 'L', 1, 0))

> -----Original Message-----
> From: Baron Schwartz [mailto:baron@stripped] 
> Sent: September 28, 2007 1:00 PM
> To: Beauford
> Cc: mysql@stripped
> Subject: Re: Count syntax
> 
> Beauford wrote:
> > Hi,
> > 
> > I have the following line of code and I keep getting wrong 
> results from it.
> > Can someone let me know what I'm doing wrong here. I just 
> can't quite 
> > figure out the syntax that I need.
> > 
> > select count(*) as numrows, count(supportertype) as leadcar from 
> > registrar where supportertype = 'L';
> > 
> > What I want to do is count the total number of records and then the 
> > total number of records that have "L" as the supportertype 
> and then display them.
> > 
> > So I should have something like "There are 100 total records and 22 
> > with Supporter Type L".
> 
> Try this:
> 
> SELECT COUNT(*), SUM(IF(supportertype = 'L', 1, 0)) FROM registrar;
> 
> Baron
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    
> http://lists.mysql.com/mysql?unsub=1
> 
> 
> 



Thread
Count syntaxBeauford28 Sep
  • Re: Count syntaxBaron Schwartz28 Sep
    • RE: Count syntaxBeauford28 Sep
      • Re: Count syntaxMichael Dykman28 Sep
        • RE: Count syntaxCraig \(OFT\) Weston28 Sep
        • RE: Count syntaxBeauford29 Sep