按渠道计算 PV 和 UV:
------------------按指定channel_id按月求PV、UV------------
drop table if exists tmp_pvuv;
create table tmp_pvuv
as
select
t1.channel_id, --渠道编号
t2.year_month, --年份月份
count(distinct t2.visitor_trace) as UV, --UV
sum(t2.pv) as PV --PV
from tmp_wangbo3_092502_channelid t1
join
(select
from_unixtime(unix_timestamp(dt,'yyyyMMdd'),'yyyy-MM') as year_month,
pvalue,
visitor_trace,
pv
from dw.kn2_traf_web_log_total --流量表
where dt>='20160101' and dt<='20170630' --2016年1月1日至2017年6月30日
) t2 on t1.channel_id=t2.pvalue
group by t1.channel_id,t2.year_month --按channel_id分组
;