I need to get the first 10 rows per page, that returns the sum of values grouped by roomId. And have a footer to display the aggregated value, beyond limit.
SELECT roomId, SUM(value) FROM table A
GROUP BY roomId
WITH ROLLUP
LIMIT 0,10
Issue is I need the summary generated by rollup to return the sum value of all the rooms, even those outside limit (page), (aggregation should not use limit)
Example data
+--------+------------+
| roomId | Sum(value) |
+========+============+
| 1 | 10 |
+--------+------------+
| 1 | 10 |
+--------+------------+
| 1 | 20 |
+--------+------------+
| 1 | 5 |
+--------+------------+
| 2 | 10 |
+--------+------------+
| 2 | 20 |
+--------+------------+
| 2 | 30 |
+--------+------------+
| 3 | 10 |
+--------+------------+
| 3 | 20 |
+--------+------------+
| NULL | 135 |
+--------+------------+
However I'd like to get the rollup to sum the value of all the rooms not all just the displayed 10 first rows, the aggregation should sum all database rows, even if the user is just reading the first 10 pages.
so the rollup should look like:
+--------+------------+
| roomId | Sum(value) |
+========+============+
| ... | ... |
+--------+------------+
| NULL | 58935 |
+--------+------------+
I know I can do 2 different queries, or use an UNION ALL, but is that true? Can't be done with rollup? Rollup would be quicker then using 2 different queries.