When to use GROUPING SETS, CUBE and ROLLUP

前端 未结 3 1058
盖世英雄少女心
盖世英雄少女心 2021-01-30 22:08

I have recently learned about GROUPING SETS, CUBE and ROLLUP for defining multiple grouping sets in sql server.

What I am asking is under what circumstances do we use th

3条回答
  •  别那么骄傲
    2021-01-30 22:40

    I find they are good when you're producing a report and the result is not something which can be rolled up within the client.

    For example, if you're doing something with COUNT(DISTINCT...) then the result across a larger group is not necessarily the same value as the sum of the parts. Eg, across two individual days you might have 1500 visitors and 2000 visitors, but the total could be anywhere between 2000 and 3500, depending on the overlap. It's nice to do this in the client, but because the client can't tell what the overlap is, you can use GROUPING SETS to provide the answer (and then handle that extra row coming through in the report).

提交回复
热议问题