Q:

Tabular data calculation - summing in middle of table

Consider a simple query:
SELECT id, date, hours FROM employees where id=10
And the following result set:
id | date     | hours
---------------------
1   4-19-2012   4
1   4-19-2012   2.5
1   4-19-2012   1
1   4-20-2012   2
1   4-20-2012   3

I'm showing a typical HTML table output of the result set but I'd like to display a daily summation on a row underneath of that days results. 
+--------------------------------------+
| David | 4-19-2012 | 4                |
|       | 4-19-2012 | 2.5              |
|       | 4-19-2012 | 1                |
|--------------------------------------|
| TOTAL ............  7.5              |
|--------------------------------------|
| David | 4-20-2012 | 2                |
|       | 4-20-2012 | 1                |
|--------------------------------------|
| TOTAL ............ 3                 |
|--------------------------------------|
| GRAND TOTAL ..........10.5           |
+--------------------------------------+

What are some of the best ways to handle that?  There are many options.  Subquerying... putting PHP code in my view... surely there is a bettery way. 

A:

Upgraded to an answer
In MySQL, you can add extra summary rows in a table that is grouped with GROUP BY by using the WITH ROLLUP modifier:

The GROUP BY clause permits a WITH ROLLUP modifier that causes extra rows to be added to the summary output.  These rows represent higher-level (or super-aggregate) summary operations.  ROLLUP thus enables you to answer questions at multiple levels of analysis with a single query.  It can be used, for example, to provide support for OLAP (Online Analytical Processing) operations. 

With your query, you could do:
SELECT id, date, SUM(hours) AS totalhours
FROM employees
WHERE id = 10
GROUP BY id, date, hours WITH ROLLUP

