Wednesday, September 22, 2010

simulating Cube function by using Group By in MySQL

Some commercial RDBMS like DB2 has function "cube". However, MySQL (5.1.48 on my machine) does not support cube yet. It supports rollup function. but I need cube function. So, I use a group of "group by" to simulate the cube function. It might not be the best solution. But, it should be much better than making thousands queries to calculate sum values. There are two steps in this simulating,

1) listing out all possible combination of column names. The total number of group by strings will be 2^n where n = the # of columns (dimension number).

2) run each sql select query with group by clause to get sum values, which we are interested.

No comments:

Post a Comment