grouping sets 可以用于在计算分组聚合函数值的同时计算合计值
-- 查询结果group_id为NULL的那一行即为合计值 select group_id , count(distinct user_id) as user_num from table_name group by group_id grouping sets ((group_id),())
参考资料:
https://blog.csdn.net/u013053796/article/details/18620631