查询语句可以直接使用非分析函数的变量的别名

select t1.*
from 
(
select account_id, sum(recharge_money) recharge_money_total
from dw.dw_app 
where dt='2016-11-21' 
and app_id='2137'
and msgtype = 'role.recharge' 
group by account_id
order by recharge_money_total desc
limit 10000000
) t1
limit 10;

 

 

分析函数必须套一个查询,不能直接用rn <=5

select t1.*
from 
(
select account_id, sum(recharge_money) recharge_money_total, 
  row_number() over (order by sum(recharge_money) desc) as rn
from dw.dw_app 
where 
dt='2016-11-21' 
and app_id='2137'
and msgtype = 'role.recharge' 
group by account_id
) t1
where t1.rn <= 5

 

posted on 2016-11-22 15:41  凌度  阅读(338)  评论(0编辑  收藏  举报