hive sql解决关联条件中不等值连接问题及累计值的计算
2017-06-16 19:59
381 查看
工作中写的sql,本次的sql可以拓展出一些新内容,留下笔记
with a as (
select
interface
,case when action is NUll then 'null' else action end as action
, request_time*1000 as request_time
,count(request_time) as pv
from
xx_xx
where ds >= %YYYYMMDD% || '00'
and ds <= %YYYYMMDD% || '23'
group by
interface
,action
,request_time * 1000
),
b as (
select
a1.interface
,a1.action
,a1.request_time
,a1.pv
,sum(case when a1.request_time>= a2.request_time then a2.pv end) as sum_cnt --解决hive sql关联条件中不等值连接问题
from
a a1
join a a2
on
a1.interface = a2.interface
and
a1.action = a2.action
group by
a1.interface
,a1.action
,a1.request_time
,a1.pv
),
c as (
select
b.interface
,b.action
,case when b.sum_cnt / t.total_pv >=0.90 then b.request_time end as geo_time_90
,case when b.sum_cnt / t.total_pv >=0.95 then b.request_time end as geo_time_95
,case when b.sum_cnt / t.total_pv >=0.99 then b.request_time end as geo_time_99
from
b
join
(
select interface
,action
,sum(pv) as total_pv
from
a
group by
interface
,action
)t
on
b.interface = t.interface
and b.action = t.action
)
select
c.interface
,c.action
,min(geo_time_90) as geo_time_90
,min(geo_time_95) as geo_time_95
,min(geo_time_99) as geo_time_99
from
c
group by
c.interface
,c.action
with a as (
select
interface
,case when action is NUll then 'null' else action end as action
, request_time*1000 as request_time
,count(request_time) as pv
from
xx_xx
where ds >= %YYYYMMDD% || '00'
and ds <= %YYYYMMDD% || '23'
group by
interface
,action
,request_time * 1000
),
b as (
select
a1.interface
,a1.action
,a1.request_time
,a1.pv
,sum(case when a1.request_time>= a2.request_time then a2.pv end) as sum_cnt --解决hive sql关联条件中不等值连接问题
from
a a1
join a a2
on
a1.interface = a2.interface
and
a1.action = a2.action
group by
a1.interface
,a1.action
,a1.request_time
,a1.pv
),
c as (
select
b.interface
,b.action
,case when b.sum_cnt / t.total_pv >=0.90 then b.request_time end as geo_time_90
,case when b.sum_cnt / t.total_pv >=0.95 then b.request_time end as geo_time_95
,case when b.sum_cnt / t.total_pv >=0.99 then b.request_time end as geo_time_99
from
b
join
(
select interface
,action
,sum(pv) as total_pv
from
a
group by
interface
,action
)t
on
b.interface = t.interface
and b.action = t.action
)
select
c.interface
,c.action
,min(geo_time_90) as geo_time_90
,min(geo_time_95) as geo_time_95
,min(geo_time_99) as geo_time_99
from
c
group by
c.interface
,c.action
相关文章推荐
- 网站无法连接sql sever数据库的一些问题处理,解决自己定义的数据库用户名,无法关联数据库和无法登陆数据库
- “未与信任SQL Server连接相关联”问题解决方法
- 不修改SQL_Latin1_General_CP1_CI_AS 字符集 解决中文条件查询问题
- LINQ TO SQL数据实体应该这样设计(解决多表关联问题)
- linq to sql 中,如何解决多条件查询问题,答案,用表达式树!
- asp.net中连接access数据库时,不能使用ISNull()T-SQL的问题解决
- 解决MS SQL Server 2005 无法远程连接问题。 推荐
- 在连接mysql5.1时正常,连接sql2000时就是连不上,郁闷,终于在网上找到了解答,原来是sql驱动和hibernate的兼容 性问题,现问题已解决,留此文备查.
- linq to sql 中,如何解决多条件查询问题,答案,用表达式树! (下)
- 看有没有高手能解决这个SQL远程连接失败问题
- 解决PL/SQL 8 ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务的问题
- 转:Microsoft SQL Server 2000连接问题的解决办法
- 使用MyEclipse 6.0连接SQL 2000和2005数据库(JDBC) 遇到的问题,急需解决
- 解决了c#捕获sql错误号的问题和将sql连接用application放在global中作全局变量问题
- 解决MS SQL Server 2005 无法远程连接问题
- 问题“未于信任SQLServer连接相关联”的解决
- AX中动态产生方法并且调用,解决根据不同条件产生不同SQL逻辑的问题很方便
- 如何解决 SQL Server 2000 中的连接问题
- 【SQL Server 2005 的问题】com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联。
- linq to sql 中,如何解决多条件查询问题,答案,用表达式树! (下)