hive ETL业绩报表sql怎么写
发表于:2025-01-31 作者:千家信息网编辑
千家信息网最后更新 2025年01月31日,这篇文章主要讲解了"hive ETL业绩报表sql怎么写",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"hive ETL业绩报表sql怎么写"吧!--
千家信息网最后更新 2025年01月31日hive ETL业绩报表sql怎么写
这篇文章主要讲解了"hive ETL业绩报表sql怎么写",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"hive ETL业绩报表sql怎么写"吧!
-- case4 ----========== rates ==========--app0 1app1 2app2 2app3 3app4 3app5 3app6 5app7 5app8 5app9 5CREATE EXTERNAL TABLE rates ( app_name STRING , star_rates STRING)ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'LOCATION '/tmp/db/rates';create table app_ranks as select app_name as app , star_rates as stars , NTILE(3) OVER (ORDER BY star_rates DESC) as nt , row_number() OVER (ORDER BY star_rates DESC) as rn , rank() OVER (ORDER BY star_rates DESC) as rk , dense_rank() OVER (ORDER BY star_rates DESC) as drk , CUME_DIST() OVER (ORDER BY star_rates) as cd , PERCENT_RANK() OVER (ORDER BY star_rates) as pr from rates order by stars desc;select app, stars, cd, sum(cd) OVER (PARTITION BY stars ORDER BY rn ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) from app_ranks;select app, stars, cd, sum(cd) OVER (PARTITION BY stars ORDER BY rn ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) from app_ranks;select 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 101d002 201301 102d003 201301 103d001 201302 111d002 201302 112d003 201302 113d001 201303 121d002 201303 122d003 201303 123d001 201304 131d002 201304 132d003 201304 133d001 201305 141d002 201305 142d003 201305 143d001 201306 151d002 201306 152d003 201306 153d001 201307 201d002 201307 202d003 201307 203d001 201308 211d002 201308 212d003 201308 213d001 201309 221d002 201309 222d003 201309 223d001 201310 231d002 201310 232d003 201310 233d001 201311 241d002 201311 242d003 201311 243d001 201312 301d002 201312 302d003 201312 303d001 201401 301d002 201401 302d003 201401 303d001 201402 211d002 201402 212d003 201402 213d001 201403 271d002 201403 272d003 201403 273d001 201404 331d002 201404 332d003 201404 333d001 201405 351d002 201405 352d003 201405 353CREATE 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 visitorswhere 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 visitorswhere 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_yearfrom visitors_reportwhere (domain = 'd001' or domain = 'd002') and month > '2014'order by month desc, domain asclimit 100;select month , domain , visitor , max(visitor) OVER (PARTITION BY month) as max_visitors , min(visitor) OVER (PARTITION BY month) as min_visitorsfrom visitorswhere 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_monfrom visitors) vwhere month > '20131'order by month desc, domain asc;
感谢各位的阅读,以上就是"hive ETL业绩报表sql怎么写"的内容了,经过本文的学习后,相信大家对hive ETL业绩报表sql怎么写这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
业绩
报表
学习
内容
就是
思路
情况
文章
更多
知识
知识点
篇文章
跟着
问题
实践
推送
研究
验证
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库语法错误应为id
原子光谱标准与技术数据库
ctf网络安全大赛名称叫什么
大学网络技术部工作职责
计算机软件开发公司排名
服务器不使用ssh登录
学电脑软件开发学校
扬州新时代网络安全
数据库主码外码可以一样吗
网站服务器搭建与管理pdf
深圳市爱迪斯网络技术
学校网络安全和宣传工作总结
海外华人互联网科技论坛
软件开发绩效扣工资
国内可以做cc服务器吗
数据库怎么加空格
网络安全期末考试抓包分析
服务器怎么获得人物信息
碧江分局网络安全保卫大队大队长
软件开发方案招投标
波兰软件开发收入
网络安全管理员证书能干嘛
云服务器可以用来做视频编辑吗
大展网络技术
北京哪里有服务器机房
淮安节能刀片服务器直销
数据库不等于某值的语句
安卓系统软件开发怎么收费
虚拟网络技术研究报告
电脑连服务器管理口