我有两张桌子
1.Employee
EMP_NAME,
EMP_CODE
2.Vacations
EMP_NAME,
EMP_CODE,
VACATION_START_DATE-->date type
VACATION_END_DATE-->date type,
我的问题是如何查询从table1(Employee)获取EMP_NAME
,其中今天不在table2(假期)的VACATION_START_DATE
和VACATION_END_DATE
之间..
答案 0 :(得分:0)
请试试这个:假设您没有emp_name
假期表......以及emp_code
作为两个表之间的关系。所以你可以使用join
s。
select e.emp_code, e.emp_name,
v.start_date, v.end_Date
from emp e
inner join
vacation v
on e.emp_code = v.emp_code
where not (Now() between v.start_date
and v.end_date)
;
| EMP_CODE | EMP_NAME | START_DATE | END_DATE |
-------------------------------------------------------------------------------------------
| 1 | john | December, 10 2012 00:00:00+0000 | December, 20 2012 00:00:00+0000 |
| 2 | kate | December, 20 2012 00:00:00+0000 | December, 30 2012 00:00:00+0000 |
| 3 | tim | December, 24 2012 00:00:00+0000 | January, 01 2013 00:00:00+0000 |
| 1 | john | January, 01 2013 00:00:00+0000 | January, 08 2013 00:00:00+0000 |
答案 1 :(得分:0)
不确定您是否认为“今天”是变量或系统日期,因此可能需要修改以下代码,但我认为它可能有效:
SELECT
EMP_NAME
FROM
EMPLOYEE
WHERE
NOT EXISTS (SELECT * FROM VACATIONS WHERE EMP_NAME = EMPLOYEE.EMP_NAME AND
VACATIONS.VACATION_START_DATE >= Today AND
VACATIONS.VACATION_END_DATE <= Today)