GROUPING SETS、ROLLUP、CUBE三者的使用异同

等待补充

 

 1 SELECT supplier_id, rating, COUNT(*) AS total
 2 FROM 
 3     (VALUES
 4         ('supplier1', 'product1', 4),
 5         ('supplier1', 'product2', 3),
 6         ('supplier2', 'product3', 3),
 7         ('supplier2', 'product4', 4)
 8     )
 9 AS Products(supplier_id, product_id, rating)
10 GROUP BY GROUPING SETS ((supplier_id, rating), (supplier_id), ());
11 +-------------+--------+-------+
12 | supplier_id | rating | total |
13 +-------------+--------+-------+
14 |   supplier1 |      4 |     1 |
15 |   supplier1 | (NULL) |     2 |
16 |      (NULL) | (NULL) |     4 |
17 |   supplier1 |      3 |     1 |
18 |   supplier2 |      3 |     1 |
19 |   supplier2 | (NULL) |     2 |
20 |   supplier2 |      4 |     1 |
21 +-------------+--------+-------+

 转载:https://www.deeplearn.me/3866.html

posted on 2022-08-17 14:52  大鹏的鸿鹄之志  阅读(28)  评论(0编辑  收藏  举报