hiveql查询中的条件WHERE,不返回任何结果

时间:2020-05-27 12:45:45

标签: sql hiveql where-clause hue partition-by

我在hue中运行了三个非常相似的查询,它们使用hiveql,其中两个具有条件(相反的条件)。我完全不了解结果:

select 
    distinct 
    product_id,
    price,
    rang,
    if(rang=1, 1, 0)
from (
    select 
        distinct 
        product_id, 
        price,
        row_number() OVER (PARTITION BY product_id order by col1 desc nulls last, col2 desc nulls last) rang
    from offer.offer_price
) op

===============>返回1行:

product_id    price    rang    c4
prod_1        12.99    1       1

================================================ =========

select 
    distinct 
    product_id,
    price,
    rang,
    if(rang=1, 1, 0)
from (
    select 
        distinct 
        product_id, 
        price,
        row_number() OVER (PARTITION BY product_id order by col1 desc nulls last, col2 desc nulls last) rang
    from offer.offer_price
) op
where if(rang=1, 1, 0)=1

==============>返回0行

select 
    distinct 
    product_id,
    price,
    rang,
    if(rang=1, 1, 0)
from (
    select 
        distinct 
        product_id, 
        price,
        row_number() OVER (PARTITION BY product_id order by col1 desc nulls last, col2 desc nulls last) rang
    from offer.offer_price
) op
where if(rang=1, 1, 0)=0

===============>返回1行:

product_id    price    rang    c4
prod_1        12.99    1       1

================================================ =========

为什么第三个查询返回的结果与第一个查询相同,而rang = 1?有人知道为什么吗?

非常感谢您。

Emilie

0 个答案:

没有答案