HiveQL中where后面的and 和or 处理

昨天我在尝试写一个很简单的HiveQL:语句如下

select <!subdate(date,0)!>,a.ver,a.vid,a.wid,a.type,count(*) from (select stat_date,ver,get_json_object(json,"$.vid") as vid,get_json_object(json,"$.wid") as wid,get_json_object(json,"$.type") as type from iphonevv_<!subdate(date,0)!> where  stat_date=<!subdate(date,0)!> and ver >= '3.5.0' and get_json_object(json,"$.type")=4 or  get_json_object(json,"$.type")=5 or  get_json_object(json,"$.type")=6 )a  group by a.stat_date,a.ver,a.vid,a.wid,a.type

我的想法是:stat_date=<!subdate(date,0)!> and ver >= '3.5.0',后面的都是or就行,但是结果并不是这样,出现了很多ver不是大于等于3.5.0的,我纠结了很久,都不知道是哪儿出了问题,为什么ver >= '3.5.0' 不起作用呢?今天查了下才发现,原来是where后面的and和or的问题导致。

结果后来我修改为:

select <!subdate(date,0)!>,a.ver,a.vid,a.wid,a.type,count(*) from (select stat_date,ver,get_json_object(json,"$.vid") as vid,get_json_object(json,"$.wid") as wid,get_json_object(json,"$.type") as type from iphonevv_<!subdate(date,0)!> where  stat_date=<!subdate(date,0)!> and ver >= '3.5.0' and (get_json_object(json,"$.type")=4 or  get_json_object(json,"$.type")=5 or  get_json_object(json,"$.type")=6 ))a  group by a.stat_date,a.ver,a.vid,a.wid,a.type

将or的条件放在()之内,问题就解决了。

where 后面如果有and,or的条件,则or自动会把左右的查询条件分开,即先执行and,再执行or。原因就是:and的执行优先级最高!

关系型运算符优先级高到低为:not and or

问题的解决办法是:

用()来改变执行顺序!!!!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值