2016-05-13 12 views
0

我试图弄清楚事实,HIVE不支持相关的子查询。最后,我一直在计算上个月每周在数据中存在多少项目,现在我想知道本周退出的项目数量,返回的项目或全新的项目。如果我可以使用where子查询,那么不会太难,但是如果没有它,我会很难想到一个解决方法。解决不受支持的相关问题Hive中的子查询

Select 
count(distinct item) 
From data 
where item in (Select item from data where date <= ("2016-05-10")) 
And date between "2016-05-01" and getdate() 

任何帮助将是伟大的。谢谢。

回答

1

解决方法是左连接两个结果集,其中第二个结果集列为空。

 Select count (a.item) 
      from 
       (select distinct item from data where date between "2016-05-01" and getdate()) a 
      left join (Select distinct item from data where date <= ("2016-05-10")) b 
      on a.item =b.item 
      and b.item is null 
+0

这帮助了一吨,谢谢! –

相关问题