0、基础知识
(1)pv:page view(页面访问量)
(2)uv:user view(访问人数)
(3)uv表的数据如下
(4)统计每个月的用户浏览量,"distinct"关键字是去除重复的值
select month, count(distinct id) from uv group by month;
1、union all:表联合操作
eg:统计每天和每月的用户访问量
select month, count(distinct id) from uv group by month union all select day, count(distinct id) from uv group by day;
2、grouping sets:只统计指定字段
eg:统计每天和每月的用户访问量,grouping__id是分组的组号(两个下划线)
select month, day, count(distinct id), grouping__id from uv group by month, day grouping sets(month, day);
3、with cube:统计指定字段的所有组合(包括NULL)
eg:统计每天和每月的用户访问量,grouping__id是分组的组号(两个下划线)
select month, day, count(distinct id), grouping__id from uv group by month, day with cube order by grouping__id;
4、with rollup:逐层统计指定字段
eg:统计每天和每月的用户访问量,grouping__id是分组的组号(两个下划线),组号扔按所有组合排序,但只显示逐层统计的记录
select month, day, count(distinct id), grouping__id from uv group by month, day with rollup order by grouping__id;