gpt4 book ai didi

mysql - 员工可在某个日期范围内完成任务

转载 作者:行者123 更新时间:2023-11-30 22:39:57 25 4
gpt4 key购买 nike

我一直在做一个员工工作管理项目,我有点卡住了。我有 3 个表:

1:  employees    empid,       empFirst     empLast    1            jon          smith    2            mark         road    3            jane         hall
2:  holiday    id        employee id      datestart       dateend    1         2                2015-08-07      2015-08-12    2         3                2015-07-4       2015-07-11    3         2                2015-07-20      2015-07-24
3: Task Assigned   id      taskid        assignedTo(userid)        startTask      endTask   1       1               1                     2015-07-10      2015-07-14   2       2               2                     2015-07-29      2015-07-29   3       2               3                     2015-07-18      2015-07-30   4       3               2                     2015-08-30      2015-09-03   5       4               2                     2015-09-10      2015-09-03

I'm not sure how to go about querying the tables to see who is available for a task in a date range (multiple user assigned to the same task). I have a query which I would here:

so if you take the holiday table out if the equation and just run the query below

SELECT employees.empId, employees.empFirst, employees.empLast
FROM employees
LEFT JOIN taskassigned
ON employees.empId = taskassigned.assignedTo
WHERE taskassigned.assignedTo IS NULL or
not (taskassigned.startTask BETWEEN '2015-07-29 14:30:00' AND '2015-07-29 18:30:00'
or taskassigned.endTask BETWEEN '2015-07-29 14:30:00' AND '2015-07-29 18:30:00')

我得到的结果是:

empId  empFirst empLast1      jon      smith   (he is available)2      mark     road    2      mark     road

如您所见,马克在此日期(在任务表中)不可用。

我想先查询假日表,看看他们是否在度假,然后查询任务表,看看他们是否已经有日期范围内的任务,然后结果告诉我该任务是否可用。

最佳答案

我目前无法测试,但请尝试:

SELECT employees.empId, employees.empFirst, employees.empLast
FROM employees
LEFT JOIN taskassigned
ON employees.empId = taskassigned.assignedTo
LEFT JOIN holiday
ON employees.empId = holiday.employeeId
WHERE (
taskassigned.assignedTo IS NULL
OR (
'2015-07-29 14:30:00' NOT BETWEEN taskassigned.startTask AND taskassigned.endTask
AND '2015-07-29 18:30:00' NOT BETWEEN taskassigned.startTask AND taskassigned.endTask
)
)
AND (
holiday.employeeId IS NULL
OR (
'2015-07-29 14:30:00' NOT BETWEEN holiday.dateStart AND holiday.dateEnd
AND '2015-07-29 18:30:00' NOT BETWEEN holiday.dateStart AND holiday.dateEnd
)
)

这将检查指定的开始日期是否不在分配任务的开始日期或结束日期之间,以及指定的结束日期是否不在分配任务的开始日期或结束日期之间,然后执行相同的操作假期。

关于mysql - 员工可在某个日期范围内完成任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31401008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com