3 回答

TA貢獻1802條經驗 獲得超5個贊
使用 across join生成員工和時間段的所有組合。然后使用 a left join(or not inor not exists) 過濾掉那些存在的:
select e.emp, ts.*
from employee e cross join
timeslots ts left join
scheduling s
on s.emp = e.emp and s.timeslot_id = ts.timeslot_id
where s.emp is null;

TA貢獻1847條經驗 獲得超7個贊
SELECT e.*, t.*
FROM employee e
CROSS JOIN
TimeSlot t
WHERE NOT EXISTs (
SELECT 0 FROM Scheduling s2
JOIN TimeSlot t2
ON s2.empid = e.empid
AND t2.endTime > t.StartTime
AND t2.startTime < t.EndTime
) --where there is not some other overlapping timeslot allocated
- 3 回答
- 0 關注
- 189 瀏覽
添加回答
舉報