List:General Discussion« Previous MessageNext Message »
From:Jay Blanchard Date:May 8 2002 12:25pm
Subject:RE: SQL Help:MySQL Specific
View as plain text  
[snip]
I want count of all the records from leads table where status = 0 , status
=1, status = 3....etc. This should happen in a single query, is it possible?
[/snip]

Can we see a small snippet of the table you are querying? This would help. I
am sure it can be done with a crosstab like this;

select recordFoo,
sum(if(status = '0', 1, 0)) as Status0,
sum(if(status = '1', 1, 0)) as Status1,
sum(if(status = '2', 1, 0)) as Status2
from tblFoo
group by recordFoo

returns
+-----------+---------+---------+---------+
| recordFoo | Status0 | Status1 | Status2 |
+-----------+---------+---------+---------+
| thisFoo   |       1 |      22 |     135 |
+-----------+---------+---------+---------+
| thatFoo   |       3 |       1 |       2 |
+-----------+---------+---------+---------+
|theotherFoo|       0 |     871 |       8 |
+-----------+---------+---------+---------+
| moreFoo   |      17 | 1118091 |       2 |
+-----------+---------+---------+---------+

HTH!

Jay


Thread
SQL Help:MySQL SpecificVirgosys Software8 May
  • Re: SQL Help:MySQL SpecificVictoria Reznichenko8 May
  • RE: SQL Help:MySQL SpecificJay Blanchard8 May