您的位置:首页 > 大数据

Hive中and和or的执行顺序

2017-10-25 21:21 2847 查看
      今天在网上看到hive中and的执行优先级比or高,觉得很奇怪,于是就亲自尝试了一下,发现果然如此,下面是我测试的一些简单语句:

select  1 from student where 1=0 or 1=1 and 1 = 0;

执行结果为空

select 1 from student where 1=0 or 1=1 and 1 =1;

执行结果为1

第二个select语句毫无疑问where语句后面的值返回为true,无论and或者or的优先级如何都一样,但是第一个select语句缺不是从左到右执行的,相当于select 1 from student where 1 = 0 or (1=1 and 1 = 0);

在此问一个问题,where语句后面可以跟两个in (子查询)吗   ?  如select name from student where name in (select nam from student) and name in (select name from student);

我试过这样写,但却是错误的,错误如下:



这样的写法有什么问题?如何才是正确的写法?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息