Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
thiscatis
- Forum Contributor
- Posts: 434
- Joined: Thu Jul 20, 2006 11:00 am
Post
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?

Last edited by
thiscatis on Tue May 01, 2007 7:39 am, edited 1 time in total.
-
jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Post
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.
-
thiscatis
- Forum Contributor
- Posts: 434
- Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis »
you da man.