hive sql 常用的语句
月表(26号-25号)
动态分区
case when subStr(cp,7,2) >= 26 then from_unixtime(unix_timestamp(subStr(cp,1,8),'yyyyMMdd') + 3600*24*10,'yyyyMM')
when subStr(cp,7,2) <26 then concat(subStr(cp,1,4), subStr(cp,5,2)) else '' end
周表
concat(substr(cp,1,4),'-',weekofyear(DATE(from_unixtime(unix_timestamp(substr(cp,1,8),'yyyymmdd'),'yyyy-mm-dd')))) as cp
动态分区
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nostrict;
set hive.exec.max.dynamic.partitions.pernode=1000;
insert overwrite table tb_ads_company_app_distinct_week partition(cp)
--下面没有as
select ..... cp from tb_name;
--cp from前面那个一定是动态分区的字段
静态分区
insert overwrite table tb_ads_company_app_count_day partition(cp='${batchid}')
排序
(select * from
(select *,row_number() over (partition by 字段1 order by 时间字段 desc) as rn from 表名 where 字段2>0) m
where m.rn=1) a