根据条件选择班次

编程入门 行业动态 更新时间:2024-10-11 17:20:36
本文介绍了根据条件选择班次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

I have three tables such as employees,Time slots and Scheduling . For example Time Slots table : id time 1 08:00:00 10:00:00 2 10:00:00 12:00:00 3 16:00:00 18:00:00 4 08:00:00 16:00:00 5 14:00:00 18:00:00 Employee Table: EMP1 EMP2 EMP3 EMP4 Scheduling table : EMP TIMESLOTS ID EMP1 1 EMP2 2 EMP3 4

I need to show the list of free employees in the time slots in a Gridview, ie since EMP3 is allocated in ( 08:00:00 16:00:00) ,then it should not be shown in any time slots between 08:00:00 16:00:00 ,but can be shown in any timeslot before 08:00:00 and after 16:00:00 ,similarly for all the scheduled Employees . If any of the employees is not scheduled on any time slots ,then that employee should be available in every time slots . ie ,EMP5 should be available in all time slots .

我尝试过:

What I have tried:

My output should be like this : EMPLOYEES FREE TIME SLOTS EMP1 10:00:00 12:00:00 EMP1 14:00:00 18:00:00 EMP1 16:00:00 18:00:00 EMP2 08:00:00 10:00:00 EMP2 16:00:00 18:00:00 EMP2 14:00:00 18:00:00 EMP3 16:00:00 18:00:00 EMP4 08:00:00 10:00:00 EMP4 10:00:00 12:00:00 EMP4 16:00:00 18:00:00 EMP4 08:00:00 16:00:00 EMP4 14:00:00 18:00:00

推荐答案

;WITH cte AS ( SELECT a.name, CASE WHEN c.slotid IS null THEN 0 ELSE c.slotid END AS slotid FROM #employees AS a LEFT JOIN #schedules AS c ON a.name LIKE c.empname ) SELECT a.name, b.timestart, b.timeend FROM cte AS a INNER JOIN #timeslots AS b ON a.slotid <> b.id

BTW,您的预期输出是错误的。有五个时间段,因此员工1,2和3将有五个可用的时隙,而不是四个,emp4将有五个。

BTW, your expected output is wrong. There are five time slots, so employees 1, 2, and 3 will have FIVE available timeslots, not four, and emp4 will have five.

name slotid timestart timeend emp1 2 10:00:00.0000000 12:00:00.0000000 emp1 3 16:00:00.0000000 18:00:00.0000000 emp1 4 08:00:00.0000000 16:00:00.0000000 emp1 5 14:00:00.0000000 18:00:00.0000000 emp2 1 08:00:00.0000000 10:00:00.0000000 emp2 3 16:00:00.0000000 18:00:00.0000000 emp2 4 08:00:00.0000000 16:00:00.0000000 emp2 5 14:00:00.0000000 18:00:00.0000000 emp3 1 08:00:00.0000000 10:00:00.0000000 emp3 2 10:00:00.0000000 12:00:00.0000000 emp3 3 16:00:00.0000000 18:00:00.0000000 emp3 5 14:00:00.0000000 18:00:00.0000000 emp4 1 08:00:00.0000000 10:00:00.0000000 emp4 2 10:00:00.0000000 12:00:00.0000000 emp4 3 16:00:00.0000000 18:00:00.0000000 emp4 4 08:00:00.0000000 16:00:00.0000000 emp4 5 14:00:00.0000000 18:00:00.0000000

更多推荐

根据条件选择班次

本文发布于:2023-11-30 06:21:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:班次   条件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!