List:General Discussion« Previous MessageNext Message »
From:Pete Harlan Date:May 13 2003 11:08pm
Subject:Re: count()
View as plain text  
select sum(status = 'pending'  ) as numPending,
       sum(status = 'active'   ) as numActive,
       sum(status = 'cancelled') as numCancelled
from   <table>

ought to get you what you want.

--Pete


On Tue, May 13, 2003 at 03:36:24PM -0700, Eric Anderson wrote:
> 
> I'm not sure if I'm just having problems thinking today but if you've
> got a field:
> 
> status enum('pending','active','cancelled') NOT NULL default 'pending'
> 
> and you want to get a total of each the entries, is there any way to do
> it in one pass, as opposed to:
> 
> select count(*) from <table> where status='pending'
> select count(*) from <table> where status='active'
> ...
> 
> mysql,sql
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
> 
Thread
count()Eric Anderson14 May
  • Re: count()Jeff Shapiro14 May
  • Re: count()Dan Nelson14 May
  • Re: count()Paul DuBois14 May
  • RE: count()Jennifer Goodie14 May
  • Re: count()Keith C. Ivey14 May
  • Re: count()(Pete Harlan)14 May
  • Re: count()Matt Silva15 May
Re: count()Steve Edberg14 May
  • Re: count()CR14 May
Re: count()Steve Edberg14 May
RE: count()Eric Anderson14 May
RE: count()Mike Hillyer14 May