请问这几个查询语句的区别以及条件语句的算法,高手帮忙啊!!!
1,select * from table WHERE STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND DUTY_TYPE_ID = '4 ' OR DUTY_TYPE_ID = '1 '
2, select * from table WHERE STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND DUTY_TYPE_ID = '1 ' OR DUTY_TYPE_ID = '4 '
3, select * from table WHERE STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND DUTY_TYPE_ID = '1
4, select * from table WHERE STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND DUTY_TYPE_ID = '4 '
以下是查询结果:
1:2957条记录
2:2013条记录
3:1613条记录
4:53条记录
为什么1和2的结果会不一样呢?
为什么3和4的和跟1和2也都不相等呢?
ORACLE的条件是怎么运算的阿?高手指点一下,在此谢过!!
------解决方案--------------------前两句可看成如下语句:
1,select * from table WHERE (STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND DUTY_TYPE_ID = '4 ') OR DUTY_TYPE_ID = '1 '
2, select * from table WHERE (STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND DUTY_TYPE_ID = '1 ') OR DUTY_TYPE_ID = '4 '
条件不同,结果当然不同啊。
ORACLE的条件是怎么运算的阿
----------------------------------
学过程序的话应该知道的。
------解决方案--------------------1,select * from table WHERE STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND ( DUTY_TYPE_ID = '4 ' OR DUTY_TYPE_ID = '1 ' )
2, select * from table WHERE STATUS_ID = '1 ' AND ON_TIME <091500 AND ON_TIME > = 083000 AND ( DUTY_TYPE_ID = '1 ' OR DUTY_TYPE_ID = '4 ' )
加上括号,调整下运算的优先级,使 or 优先 ,这样就和 3、4 的合计 一样了