【问题标题】:Selecting Value Between a Range of Values in hive在 hive 的值范围内选择值
【发布时间】:2019-09-30 16:07:50
【问题描述】:

在费率表中选择费率,值介于两种货币之间 我在 where 条件下使用子查询,但 Hive 不支持它们

选择 r1.currency_code,r1.rate

从速率 r1

其中 r1.rate >=(从汇率 r2 中选择 r2.rate,其中 r2.currency_code='GBP')

and r1.rate

应该选择GBP和ILS之间的汇率,但是hive不支持查询

【问题讨论】:

    标签: hive conditional where-clause


    【解决方案1】:

    在过滤之前使用条件聚合将 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
    

    【讨论】:

    • +----------------+----------------+------- +--+ |基本货币 |货币代码 |率 | +----------------+----------------+--------+--+ +--- -------------+----------------+--------+--+
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 2011-06-06
    • 2021-08-20
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多