这篇文章主要讲解了"蜂巢抽取、转换、加载至目的端(extract-transform-load的缩写)业绩报表结构化查询语言怎么写",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"蜂巢抽取、转换、加载至目的端(extract-transform-load的缩写)业绩报表结构化查询语言怎么写"吧!
案例四
-============费率============-
app01
app12
app22
app33
app43
app53
app65
app75
app85
app95
CREATEEXTERNALTABLErates(
app_nameSTRING
,star_ratesSTRING
)
行格式以“\ t”分隔
LOCATION '/tmp/db/rates ';
createtableapp_ranksas
selectapp_nameasapp
,star _ ratesasstars
,NTILE(3)OVER(orderBystar _ rates desc)为nt
,row _ number()OVER(ORDERBYstar _ ratesdessc)asrn
,rank()OVER(ORDERBYstar _ ratesdessc)asrk
,dense _ rank()OVER(ORDERBYstar _ rates desc)作为drk
,CUME _ DIST()OVER(按星级排序)ascd
,PERCENT _ RANK()OVER(orderBystar _ rates)aspr
运费率
orderbystarsdesc
;
从app_ranks中选择pp、stars、cd、sum(CD)OVER(partitionbytarorderbyrnrowsetwithebounddreceving和current ow);
从app_ranks中选择pp、stars、cd、sum(CD)OVER(partitionbytarorderbyrnrows tweencurrentwandnundfollowing);
s
elect app, stars, cd, sum(cd) OVER (PARTITION BY stars ORDER BY rn ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) from app_ranks;
select app, stars, rn, lead(rn) OVER (PARTITION BY stars ORDER BY rn), lag(rn) OVER (PARTITION BY stars ORDER BY rn) from app_ranks;
--========== visitors ==========--
d001 201301 101
d002 201301 102
d003 201301 103
d001 201302 111
d002 201302 112
d003 201302 113
d001 201303 121
d002 201303 122
d003 201303 123
d001 201304 131
d002 201304 132
d003 201304 133
d001 201305 141
d002 201305 142
d003 201305 143
d001 201306 151
d002 201306 152
d003 201306 153
d001 201307 201
d002 201307 202
d003 201307 203
d001 201308 211
d002 201308 212
d003 201308 213
d001 201309 221
d002 201309 222
d003 201309 223
d001 201310 231
d002 201310 232
d003 201310 233
d001 201311 241
d002 201311 242
d003 201311 243
d001 201312 301
d002 201312 302
d003 201312 303
d001 201401 301
d002 201401 302
d003 201401 303
d001 201402 211
d002 201402 212
d003 201402 213
d001 201403 271
d002 201403 272
d003 201403 273
d001 201404 331
d002 201404 332
d003 201404 333
d001 201405 351
d002 201405 352
d003 201405 353
CREATE EXTERNAL TABLE visitors (
domain STRING
, month STRING
, visitor STRING
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION '/tmp/db/visitors';
select * from visitors where domain = 'd001';
select domain
, month
, visitor
, first_value(visitor) OVER (PARTITION BY domain ORDER BY month DESC)
, last_value(visitor) OVER (PARTITION BY domain ORDER BY month DESC)
, lead(visitor) OVER (PARTITION BY domain ORDER BY month DESC)
, lag(visitor) OVER (PARTITION BY domain ORDER BY month DESC)
from visitors
where domain = 'd001';
select domain
, month
, visitor
, first_value(visitor) OVER (PARTITION BY domain ORDER BY month DESC)
, last_value(visitor) OVER (PARTITION BY domain ORDER BY month DESC)
, lead(visitor, 1, 0) OVER (PARTITION BY domain ORDER BY month DESC)
, lag(visitor, 1, 0) OVER (PARTITION BY domain ORDER BY month DESC)
, lead(visitor, 12, 0) OVER (PARTITION BY domain ORDER BY month DESC)
, lag(visitor, 12, 0) OVER (PARTITION BY domain ORDER BY month DESC)
from visitors
where domain = 'd001';
create table visitors_report as
select domain
, month
, visitor
, lead(visitor, 1, 0) OVER (PARTITION BY domain ORDER BY month DESC) as last_mon
, visitor - lead(visitor, 1, 0) OVER (PARTITION BY domain ORDER BY month DESC) as delta_mon
, lead(visitor, 12, 0) OVER (PARTITION BY domain ORDER BY month DESC) as last_year
, visitor - lead(visitor, 12, 0) OVER (PARTITION BY domain ORDER BY month DESC) as delta_year
from visitors
;
select * from visitors_report where domain = 'd001' and month > '2014';
select month
, domain
, visitor
, last_mon
, last_year
from visitors_report
where (domain = 'd001' or domain = 'd002') and month > '2014'
order by month desc, domain asc
limit 100;
select month
, domain
, visitor
, max(visitor) OVER (PARTITION BY month) as max_visitors
, min(visitor) OVER (PARTITION BY month) as min_visitors
from visitors
where month > '2014'
order by month desc, domain asc;
select *
from (
select month
, domain
, visitor
, max(visitor) OVER (PARTITION BY domain ORDER BY month DESC ROWS BETWEEN CURRENT ROW AND 12 FOLLOWING) as max_visitors_last_12_mon
, min(visitor) OVER (PARTITION BY domain ORDER BY month DESC ROWS BETWEEN CURRENT ROW AND 12 FOLLOWING) as min_visitors_last_12_mon
from visitors
) v
where month > '20131'
order by month desc, domain asc;
感谢各位的阅读,以上就是“hive ETL业绩报表sql怎么写”的内容了,经过本文的学习后,相信大家对hive ETL业绩报表sql怎么写这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/156274.html