join—为什么配置单元sql在select语句中返回一个特定列的空值,而该列具有所有的双精度值?

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

我正在使用配置单元sql。版本为hive 1.1.0-cdh5.14.0。在下面的示例中,sp.close是一个类型为double的列。我检查了sp.column,绝对没有空值。然而,在下面的select语句中,sp.close显示所有空值。为什么?

select
    step1.*,
    sp.close

from
    step1 left join stockprices2 sp on (
        step1.symbol = sp.symbol and
        step1.year = sp.year and
        step1.startmonth = sp.month and
        step1.startday = sp.day and
        step1.sector = sp.sector
    )

;
3bygqnnd

3bygqnnd1#

很可能,你的 left join 未在中的行中找到匹配项 stockprices2 . 在这种情况下,来自 step1 保留,但中的所有列 stockprices2null 在结果集中。这是通过设计数据库如何发出 left join 空出来了。
你可以通过改变 left join 到一个 inner join :您应该返回较少的行(其中没有匹配项) stockprices2 ,中的行 step1 从结果集中删除),并且 null 中的值 sp.close .
或者可以添加 left join 环境条件 select 子句,并确保 null 我也是。

select
    st.*,
    sp.close,
    sp.symbol   -- null too
from step1 st 
left join stockprices2 sp 
    on  st.symbol = sp.symbol 
    and st.year = sp.year 
    and st.startmonth = sp.month 
    and st.startday = sp.day 
    and st.sector = sp.sector

旁注:连接条件周围的括号是多余的。

相关问题