Hive查询以在条件不满足时从表返回结果

时间:2019-12-03 20:00:51

标签: hive

我正在寻找配置单元查询,该查询仅在DataSet中没有主题:历史记录时才返回所有结果。请注意,数据集每次都会更改

数据集:

enter image description here 数据集:

enter image description here

因此,上面的第一个数据集具有带有Subject:History的记录,因此应返回0条记录,而第二个数据集不具有subject:history,因此在这种情况下应返回所有4条记录

1 个答案:

答案 0 :(得分:0)

分析函数将为所有行返回相同的history_exists标志:

select id, name, age, subject, score
from
(
 select t.*, max(case when t,subject='History' then true else false end) over() as history_exists --the same value for all dataset
  from your_table t
)s
where NOT history_exists;