oracle 9i 中Select语句问题
发布网友
发布时间:2022-04-08 07:33
我来回答
共4个回答
热心网友
时间:2022-04-08 09:03
WHERE T.CFG_ID = '7'
AND (sys_date BETWEEN T.VAL AND T.VAL1) or (sys_date BETWEEN T.VAL2 AND T.VAL3);
等同于
WHERE (T.CFG_ID = '7' AND (sys_date BETWEEN T.VAL AND T.VAL1))
or (sys_date BETWEEN T.VAL2 AND T.VAL3);
和你后面写的条件是两码事。
也就是最早的语句,只要sys_date BETWEEN T.VAL2 AND T.VAL3,T.CFG_ID 不用等于'7',也算条件通过的。
热心网友
时间:2022-04-08 10:21
SELECT COUNT(*)
INTO FLAG
FROM SYS_CONFIG T
WHERE T.CFG_ID = '7'
AND (sys_date BETWEEN T.VAL AND T.VAL1) or (sys_date BETWEEN T.VAL2 AND T.VAL3);
这是你最开始有问题的语句,它跟下面的语句是等效的:
SELECT COUNT(*)
INTO FLAG
FROM SYS_CONFIG T
WHERE (T.CFG_ID = '7'
AND (sys_date BETWEEN T.VAL AND T.VAL1)) or (sys_date BETWEEN T.VAL2 AND T.VAL3);
你的想法是,T.CFG_ID 必须要等于‘7’,但是因为or的优先级比and要低,所以只要满足sys_date BETWEEN T.VAL2 AND T.VAL3就会被count计数、而不必满足T.CFG_ID =‘7’
热心网友
时间:2022-04-08 11:55
未明确列,有两个deptno,加个所属表就ok了
select emp.deptno, ename, sal from emp join (select deptno, max(sal) max_sal from emp group by deptno) t on (emp.sal=t.max_sal and emp.deptno=t.deptno);
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
vaela
热心网友
时间:2022-04-08 13:47
and 优先级高于 or,语法如此