![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
hive
山顶看数据
这个作者很懒,什么都没留下…
展开
-
hql求一个范围内最大值
主要明白的是字符串是可以进行排序的,但是不能进行最极致,比如这里的日期这道题就是求在开始时间和结束时间里面的最大的数值,而且还是把两列变成一例的方法最终查询的答案select user_id, max(num) max_numfrom ( select id, user_id, dt, sum(p) over(partition by user_id order by dt) num from .原创 2021-12-07 11:20:09 · 289 阅读 · 0 评论 -
字节数仓实习生面试sql题
题目要求id cnt url1 12 a2 21 f1 32 e相关说明:cnt相当于日期这里需要把这个表拆分成如下的类型id 最大日期 url 最小日期 url1 32 e 12 a当时脑子突然一热,在面试官面前有点紧张,这道题也就没有做出来,面试完之后自己又重新审视了一下这道题,具体的sql语句如下select t3.id,t3.cnt,t3.url.原创 2021-12-07 15:02:48 · 768 阅读 · 0 评论 -
hive中常见的日期函数
常见hive的时间函数1、时间戳转化为日期函数from_unixtime('1566390082')from_unixtime('1566390082', 'yyyy-MM-dd')from_unixtime('1566390082', 'yyyyMMdd')2019-08-21 20:21:22 2019-08-21 201908212、将日期转换为时间戳unix_timestamp('2019-08-21 20:21:22')unix_timestamp('2019-08-.原创 2022-01-26 11:22:51 · 8117 阅读 · 0 评论 -
SQL练习第一题
题目表名:macro_index_data字段名:数据期(年月) 地区代码 指标代码 指标类型 (增速、总量) 指标值 数据更新时间occur_period area_code index_code index_type index_value update_time说明:罗湖区的区划代码为 440305000000、GDP指标代码为gmjj_jjzl_01、指标类型的枚举值分别是增速(TB)、总量(JDZ)问题请写出,2020年4个季度中G原创 2022-01-26 11:20:46 · 1962 阅读 · 0 评论 -
hive调优第一部分
1、Explain查看执行计划explain可以查看执行计划-- 创建大表create table bigtable(id bigint,t bigint,uid string,keyword string,url_rank int,click_num int,click_url string)row format delimited fields terminated by '\t';-- 创建小表create table smalltable(id bigint,t bigint,原创 2021-12-25 16:56:06 · 887 阅读 · 0 评论 -
HQL语句的调优
1、去重语句(用group by 来代替distinct)Group by 也有去重的功能,具体内容如下select distinct customer_idfrom test_join_order;=>select customer_idfrom test_join_ordergroup by customer_id;在极大的数据量(且很多重复值)时,可以先group by去重,在count()计数,效率高于count(distinct col)create tabl原创 2021-12-12 11:47:58 · 835 阅读 · 0 评论 -
Hive——分区
内部表与外部表的相互转换alter table student2 set tblpropertes('external'='TRUE')desc formatted student创建一级分区表create table if not exists country(province STRING,city STRING)partitioned by(dates STRING)row format delimitedfields terminated by ',';load data原创 2021-09-26 19:23:26 · 186 阅读 · 0 评论