Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

more specific count() in queries

Codes here !

Moderators: macek, egami, gesf

more specific count() in queries

Postby beefsack » 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.
beefsack
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Dec 11, 2002 6:32 pm
Location: Australia

Postby Xerpher » 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.
Xerpher
New php-forum User
New php-forum User
 
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Postby beefsack » Sun Mar 23, 2003 10:59 pm

yeah, thats what i was afraid of.
beefsack
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Dec 11, 2002 6:32 pm
Location: Australia


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron