昨天我在尝试写一个很简单的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
结果后来我修改为:
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
where 后面如果有and,or的条件,则or自动会把左右的查询条件分开,即先执行and,再执行or。原因就是:and的执行优先级最高!
关系型运算符优先级高到低为:not and or
问题的解决办法是:
用()来改变执行顺序!!!!