一、SQL(HIVE)
1、顺序
2、去重
-
distinct(对所有字段去重),会有时间损耗
-
group by(同样去重效果,大数据量效果比distinct好)
3、时间转换
时间戳:1627749129122,时间:2021-08-01 00:32:09。from_unixtime参数要求为整数。参考链接:时间转换
-
13位时间戳转化成时间(年月日时分秒)
select from_unixtime(cast('1627749129122'/1000 as bigint))
--from sys
运行结果:
-
时间转化成10位时间戳
select unix_timestamp('2021-08-01 00:32:09')
运行结果:
-
固定日期转化成时间戳
select unix_timestamp('2021-08-16','yyyy-MM-dd') --*1000转化成13位
select unix_timestamp('20210816','yyyyMMdd') --*1000转化成13位
select unix_timestamp('2021-08-16T10:02:41Z', "yyyy-MM-dd'T'HH:mm:ss'Z'") --*1000转化成13位
16/Mar/2021:12:25:01 +0800 转成正常格式(yyyy-MM-dd hh:mm:ss)
select from_unixtime(to_unix_timestamp('16/Mar/2021:12:25:01 +0800', 'dd/MMM/yyy:HH:mm:ss Z'))
4、排序
select row_number() over (partition by a,b order by admin_time desc) as row_desc
根据a