Adding total from different departments

Firstly a huge thank you to palindrome for helping me on my last topic and no sooner as i sort one when it leads me to another ::slight_smile:

I have alarge table of data first colum is names and next is there department and following are totals.
Is there a way that i can that i can add total for certain departments

IE if department = science then add totals
IE if department = history then add totals
name / dept / week1 / week2 / week3 / week4
bill / science / 12 / 34 / 44 / 77
bob / history / 444 / 23 / 92 / 11
dan / Maths / 34 / 41 / 71 / 67
charlies / Maths / 22 / 93 / 37 / 11

Total Science =
total History =
Total MAths =

I figure i need it to loop through till if finishes. And can kind of figure what i need to do but having dificulty searching for exactly what it is am looking for.

Sorry if this a little vague , again learning as i go along.

Thanks !

Paul

Think i may have cracked it

$query = “SELECT dept, SUM(tot1) FROM database GROUP BY dept”;

but if anyone have any more ideas then i wold be keen to hear them !

Thanks all

Sponsor our Newsletter | Privacy Policy | Terms of Service