【问题标题】:Hive query join with string as datatype使用字符串作为数据类型的 Hive 查询连接
【发布时间】:2016-06-29 22:43:13
【问题描述】:

我在 hive 中有两个表并尝试执行连接:

A表:

id  ord_time          
84  10:00:00      
84  12:00:00      
84  15:00:00 
84  4:00:00 

数据类型:

Id  : int
ord_time : String

表 B:

id  time_desc   beg_tm        end_tm
84  Late Night  00:00:00      04:59:59
84  Break Fast  05:00:00      10:29:59
84  Dinner      16:00:00      20:59:59        
84  Lunch       11:00:00      13:59:59
84  Snack       14:00:00      15:59:59  

数据类型:

Id  : int
time_desc : String
beg_tm : String
end_tm : String 

查询:

Select a.ord_time,b.id,b.time_desc,b.beg_tm,b.end_tm
from Table A a,Table B b
where a.id = b.id
and a.ord_time between b.beg_tm and b.end_tm

当我运行上述查询时,结果为 Null。

我希望输出是:

id  ord_time    time_desc
84  10:00:00    BreakFast
84  12:00:00    Lunch
84  15:00:00    Snack
84  04:00:00    Late Night

【问题讨论】:

  • 您的时间数据中是否有前导或尾随空白字符?我还注意到一个表没有前导零,但另一个有(这不起作用)

标签: sql string join hive


【解决方案1】:

之间也没有为我工作。然后我想

name between "a" and "b" 

等价于

name >="a" and name <="b"

所以我尝试了这个。它对我有用。试试你的情况。希望它对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2022-09-30
    相关资源
    最近更新 更多