Though this is an age old concept, but after seeing the ignorance factor of many regarding this, I thought of writing a bit about it. ROLLUP is a GROUP BY modifier that adds extra rows to the output which contain summary data. At each level of aggregation the aggregated column is filled with a NULL value.
Let's see a small example. I know the values are too small for the data presented, but just to keep it readable.
1: mysql> CREATE TABLE `rollup_1` (
2: `url` varchar(255) DEFAULT NULL,
3: `year` int(11) DEFAULT NULL,
4: `country` char(2) DEFAULT NULL,
5: `visit` int(11) DEFAULT NULL
6: ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
7: Query OK, 0 rows affected (0.01 sec)
8:
9: mysql> SELECT * FROM rollup_1;
10: +----------------------+------+---------+-------+
11: | url | year | …[Read more]