[thelist] Better way to do this (SQL)?
Sarah Sweeney
mr.sanders at designshift.com
Tue May 18 09:20:43 CDT 2004
> Thanks a lot, it really did, and I have a better understanding of how
> SQL works. Unfortunately the version of MySQL that I'm using doesn't
> support subselects -- but as soon as we decide to do the next upgrade, I
> should be able to use your query.
I had a similar issue not too long ago, and had a solution presented to
me by someone on thelist (sorry, not sure who). Here is that solution
tailored to your needs:
SELECT COUNT(*) AS TotalBoth,
SUM(CASE WHEN sex = 'male' THEN 1 ELSE 0 END) AS TotalMale,
SUM(CASE WHEN sex = 'female' THEN 1 ELSE 0 END) AS TotalFemale
FROM table
This might not be exactly right, but hopefully it will put you on the
right track.
Sarah
--
Sarah Sweeney
Web Developer/Programmer
http://sarah.designshift.com/
More information about the thelist
mailing list