MySql Function
MySql Rollup function : The GROUP BY clause permits a WITH ROLLUP modifier that causes summary output to include extra rows that represent higher-level (that is, super-aggregate) summary operations. ROLLUP thus enables you to answer questions at multiple levels of analysis with a single query. For example, ROLLUP can be used to provide support for OLAP (Online Analytical Processing) operations. Suppose that a sales table has year , country , product , and profit columns for recording sales profitability: CREATE TABLE sales ( year INT, country VARCHAR(20), product VARCHAR(32), profit INT ); To summarize table contents per year, use a simple GROUP BY like this: mysql> SELECT year, SUM(profit) AS profit FROM sales GROUP BY year ASC; +------+--------+ | year | profit | +------+--------+ | 2000 | 4525 | | 2001 | 3010 | +------+--------+ ...