hive查询where join,在Hive中使用where子句编写一个嵌套的select语句

I have a requirement to do a nested select within a where clause in a Hive query. A sample code snippet would be as follows;

select *

from TableA

where TA_timestamp > (select timestmp from TableB where id="hourDim")

Is this possible or am I doing something wrong here, because I am getting an error while running the above script ?!

To further elaborate on what I am trying to do, there is a cassandra keyspace that I publish statistics with a timestamp. Periodically (hourly for example) this stats will be summarized using hive, once summarized that data will be stored separately with the corresponding hour. So when the query runs for the second time (and consecutive runs) the query should only run on the new data (i.e. - timestamp > previous_execution_timestamp). I am trying to do that by storing the latest executed timestamp in a separate hive table, and then use that value to filter out the raw stats.

Can this be achieved this using hive ?!

解决方案

However, often you can use a JOIN statement instead to get to the same result:

https://karmasphere.com/hive-queries-on-table-data#join_syntax

For example, this query:

SELECT a.KEY, a.value

FROM a

WHERE a.KEY IN

(SELECT b.KEY FROM B);

can be rewritten to:

SELECT a.KEY, a.val

FROM a LEFT SEMI JOIN b ON (a.KEY = b.KEY)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值