我有两张桌子
1.员工
EMP_NAME,
EMP_CODE
2.假期
EMP_NAME,
EMP_CODE,
VACATION_START_DATE-->date type
VACATION_END_DATE-->date type,
我的问题是如何查询EMP_NAME
从 table1(Employee) 获取今天不在中间VACATION_START_DATE
的VACATION_END_DATE
table2(Vacations)..
请试试这个:假设你没有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 |
不确定您的意思是“今天”是变量还是系统日期,因此可能需要修改以下代码,但我认为它可能有效:
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)