简体   繁体   English

操作sql表获取一天超额预定的员工

[英]Manipulating a sql table to get employees who are overbooked in a day

I have 3 Tables我有3张桌子

1. Employees (empid, lname, fname, emptype, cellphone, homphone, ftpt)
2. Schedule(date, empid, dept_name, start_time, shift_length)
3. Departments(dept_name, dept manager)`

We have to generate a table listing all employees who are overbooked by being scheduled more than once a day.我们必须生成一个表格,列出所有因每天安排超过一次而超额预定的员工。

The final table after the select statement should look like this : select 语句后的最终表应如下所示:

it is ordered by the employee ID.它是按员工 ID 排序的。

Here is the create table for the 3 tables:这是 3 个表的创建表:

CREATE TABLE Departments(department_name VARCHAR(30));
CREATE TABLE Employees(empid int PRIMARY KEY NOT NULL, lname VARCHAR(20) NOT NULL, fname VARCHAR(20) NOT NULL, emptype VARCHAR(5) NOT NULL, cellphone VARCHAR(20), homephone VARCHAR(20), ftpt VARCHAR(3) NOT NULL);
CREATE TABLE Schedule(date VARCHAR(20) NOT NULL, empid INT NOT NULL, department VARCHAR(30) NOT NULL, start_time VARCHAR(5) NOT NULL, shift_length INT NOT NULL );

Sample data Schedule EMPLOYEES样本数据安排员工

Files with data - https://drive.google.com/drive/folders/1hSf4rbGOvqrTZVyPaveF6fUAKB29Q2o_?usp=sharing包含数据的文件 - https://drive.google.com/drive/folders/1hSf4rbGOvqrTZVyPaveF6fUAKB29Q2o_?usp=sharing

Some of the column names you gave are inconsistent, so you may need to change some of them to match what is actually in your database.您提供的某些列名不一致,因此您可能需要更改其中一些列名以匹配数据库中的实际内容。 But this should get you started.但这应该让你开始。

SELECT empid, lname as lastName, fname as firstName, date as [OVERBOOKED DATE], start_time as sfrom, Departments.dept_name as dname, dept_manager as MANAGER FROM Employees JOIN Schedule ON Employees.empid=Schedule.empid JOIN Departments on Schedule.dept_name=Departments.dept_name WHERE empid IN (SELECT empid FROM Schedule WHERE COUNT(*) > 1 GROUP BY date, empid)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示在一周中的一天中雇用人数最多的所有雇员 - Show all employees who were hired on the day of the week on which the highest number of employees were hired SQL:给出收入超过经理的员工姓名 - SQL: Give the names of employees who earn more than their manager 获得加薪后低于平均工资的员工 - Get Employees Who Are Below Average Salary After A Raise 使用 MySQL 获取拥有多个电话号码的员工 - Get the employees who have more than one phone number with MySQL 用于查找监督最大员工数量的经理姓名的SQL查询是什么? - What is the SQL query for finding the name of manager who supervises maximum number of employees? 用 SQL 编写查询以显示过去担任销售代表的员工的当前工作的详细信息 - Write a query in SQL to display the details of the current job for those employees who worked as a Sales Representative in the past 什么是SQL查询来查找比任何其他主管监督更多员工的员工姓名? - What is the SQL query to find the name of employee who supervises more employees than any other supervisor? 如何获得1983年1月1日以后加入的部门明智员工的人数 - how to get no of employees dept wise who joined after 1st jan 1983 获取与至少一个其他员工同时进入项目的所有员工的名字和姓氏 - Get the first and last names of all employees who entered the project at the same time as at least one other employee 如何在此sql表中找到所有员工访问的位置? - How can I find the location visited by all employees in this sql table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM