more specific count() in queries

Codes here !

Moderators: egami, macek, gesf

Post Reply

Sun Mar 23, 2003 4:15 pm

lets say for example i have a table with student names and grades. more specifically, the table is called studentResults with two feilds: studentName, grade. is it possible to do a query where the result shows the studentName (the only thing i can do atm :oops: ), a feild with the count of their A's, a feild with the count of their B's etc.

i tried this query

Code: Select all

select studentName, count(grade) where grade='A', count(grade) where grade='B' ... count(grade) where grade='F' from studentResults group by studentName;

but it dont work. im assuming you cant do a where in the middle of a query, therefore i am assuming what i am trying to do is impossible :( . i hope someone can help.

New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Sun Mar 23, 2003 5:35 pm

Give us your php code if this doesn't work (I could be wrong, I'm not the greatest at MySQL)...

Code: Select all

SELECT studentName, count(grade) FROM studentResults where grade='A' OR grade='B' ... OR grade='F' GROUP BY studentName;

If you want to count() each grade seperately I'm pretty sure you need to split this in to multiple queries.
Terra Design, my business and sole / huge PHP project... a fully dynamic and adaptive site engine.


Sun Mar 23, 2003 10:59 pm

yeah, thats what i was afraid of.

Post Reply