Page 1 of 1

[SOLVED] PHP / SQL count value

Posted: Tue May 01, 2007 7:17 am
by thiscatis
a table in my database looks like this:

School - Year - Assessment 1 - Assessment 2

name1 - 5 - 200 - 300
name1 - 6 - 250 - 350
name2 - 5 - 190 - 300
name2 - 8 - 198 - 321
name2 - 7 - 210 - 300

with the rows above results for different years of a same school

How can I count ALL the results for the first and second assessment so it will be displayed as

name1 - 450 - 650
name2 - 598 - 921

So it counts all the results for assessment 1 and two and gives it back as an int instead of displaying all the resuls seperatly...

hope this makes sense? :)

Posted: Tue May 01, 2007 7:28 am
by jayshields

Code: Select all

SELECT
  `name`, SUM(`assessment1`) AS `ass1total`, SUM(`assessment2`) AS `ass2total`
FROM
  `table`
GROUP BY
  `name`
Untested. It will be something like this.. you might need a HAVING clause in the GROUP BY though.

Edit: Just tested it. Works fine.

Posted: Tue May 01, 2007 7:38 am
by thiscatis
you da man.