ADV SQL Help Needed.
| From: | [-^-!-%- | Date: | Tue, 21 Jan 2003 12:06:52 +0000 |
| Subject: | ADV SQL Help Needed. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-132388@lists.php.net to get a copy of this message | ||
Hello everyone,
I need help with the following query.
I have a table with a column named 'RISK_LEVEL'.
RISK_LEVEL can hold three values: Low, Moderate, and High.
I need a query that counts the number of occurences of each option.
Now, I know I can do
'select count(risk_level) as levelCount where risk_level=low'
for each level (low, moderate, and high). But, I was wondering if there's
anyway to merge the queries into one.
I'm looking for something like
"select count(risk_level='low') as lowCount, count(risk_level='moderate')as
modCount, count(risk_level='high') as highCount "
Which will return, lowCount = 1 , modCount=3, and highCount=1, for table
with
id | risk_level
1 | low
2 | moderate
3 | moderate
4 | high
5 | moderate
How do you do it? Can tha be done?
When I run the code above, I get the same number for each record. i.e.
lowCount, modCount, and highCount all come out to 5--which is the number
of records in the table.
Is this possible, or should I just run multiple queries?
Please help.
=P e p i e D e s i g n s
www.pepiedesigns.com
Providing Solutions That Increase Productivity
Web Developement. Database. Hosting. Multimedia.