Summarizing data using ROLLUP |
|||||||||||||
Let's compute total income funds per each point of reception in the Income table. This is easy to do with the query Assume that you need to get sum over all the points in addition, i.e. the result should look like this
The problems analogous to mentioned above are being solved with special ROLLUP clause of SELECT statement. This opportunity makes the query very simple:
Due to the fact that the values of a column must be of the same data type, point number convert to the character data type. The last query can be rewritten in another (standard) syntax form:
If DBMS does not support the ROLLUP clause, you can use either UNION or outer join (FULL JOIN) to combine two queries into one. These solutions are Below. UNION
FULL JOIN
Note that the last solution use the joining on obviously false predicate because rows from both tables, which have no coincidings, are necessary to us. |