well you see the query is important. it is easier to walk through fixing one statement then it is trying to teach proper syntax through only theory and no examples.
i understand the basis of what you are doing.
you can get the desired data through a combination of sum() and group by.
so basically, in your statements that you use to get the detailed data you want, take all of the fields except the one that you want summed out of the select but leave all of the where conditions intact.
the surround the field name with sum(), and possibly give it an alias for easy reference.
then before (if you have one) the order by clause, add a group by clause to the statement and add the field name that is for the quarters and/or users depending on how you want the data summed.
i.e.
lets take a sample table
-----------------------------------
Code:
--------------------------
| quarter | year | value |
+---------+------+-------+
| 1 | 2003 | 100 |
+---------+------+-------+
| 2 | 2003 | 100 |
+---------+------+-------+
| 3 | 2003 | 100 |
+---------+------+-------+
| 4 | 2003 | 100 |
+---------+------+-------+
| 1 | 2004 | 100 |
+---------+------+-------+
| 2 | 2004 | 100 |
+---------+------+-------+
| 3 | 2004 | 100 |
+---------+------+-------+
| 4 | 2004 | 100 |
+---------+------+-------+
ok, now, say we want to sum the data by year and show all years in the table
select year, sum(value) as total from sample group by year, order by year
This would output something like:
Code:
+------+-------+
| year | total |
+------+-------+
| 2003 | 400 |
| 2004 | 400 |
+------+-------+
now, lets say we wanted to get a sum on a quarters basis but for all years
select quarter, sum(value) as total from sample group by quarter, order by quarter
This would output something like:
Code:
+---------+-------+
| quarter | total |
+---------+-------+
| 1 | 200 |
| 2 | 200 |
| 3 | 200 |
| 4 | 200 |
+---------+-------+
now, lets say we carry the last one just a bit further and we only want to see the 1st quarter
select sum(value) as total from sample where quarter = 1 group by quarter
This would output something like:
Code:
+-------+
| total |
+-------+
| 200 |
+-------+