在配置单元中的一系列值之间选择值

z4bn682m  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(274)

在汇率表中选择汇率,其值介于两种货币之间

我在where条件中使用子查询,但hive不支持它们
选择r1.货币代码,r1.汇率
来自速率r1
其中r1.rate>=(从rate r2中选择r2.rate,其中r2.currency\u code='gbp')
r1.rate<=(从rates r3中选择r3.rate,其中r3.currency\u code='ils')
应选择gbp和ils之间的速率,但hive不支持查询

3zwjbxry

3zwjbxry1#

在筛选之前,使用条件聚合将gbp和ils速率放入列中。

select base_currency,currency_code,rate
from (select r.*
            ,max(case when currency_code='GBP' then rate end) over(partition by base_currency) as gbp_rate
            ,max(case when currency_code='ILS' then rate end) over(partition by base_currency) as ils_rate
      from rate r
      where base_currency = 'USD'
     ) r
where rate >= gbp_rate and rate <= ils_rate

相关问题