检索fromdate和todate之间的记录,传递两个日期和外键值。
我试过这个,
SELECT* FROM Test where T_ID = 1 and '2015-03-10' BETWEEN FROM_DATE and TO_DATE or '2015-03-18' BETWEEN FROM_DATE and TO_DATE;
但它返回外键记录与这些日期之间的另一个外键记录
正确的结果大小应为2。 但这里返回4。
答案 0 :(得分:2)
查询的第二部分没有给出T_ID。
select * from Test where T_ID = 1 and '2015-03-10' BETWEEN FROM_DATE and TO_DATE or T_ID = 1 and'2015-03-18' BETWEEN FROM_DATE and TO_DATE;
答案 1 :(得分:1)
您需要在OR
()
条款
SELECT* FROM Test
where T_ID = 1
and ('2015-03-10' BETWEEN FROM_DATE and TO_DATE
or '2015-03-18' BETWEEN FROM_DATE and TO_DATE);