用sql语句 假定数据库中有如下表结构: 员工(Employees) ID INT 主键 Code VARCHAR2(200) 员工编号 Name VARCHAR2(200) 员工姓名 Departmentld INT 关联部门表,如果未安排部门此字段为NULL 部门 (departments) ID INT 主键 Name VARCHAR2(200) 部门名称 1.写SQL统计出有10个员工以上的部门及相应员工数量,输出列:部门ID、 部门名称、员工数量。 3.写SQL输出全部员工清单(含未分配部门的),输出列:员工ID、 员工名称、部门名称, 2.写 SQL找出员工编号(code)列重复的员工记录,输出列:“员工ID、员工Code、员工姓名”。
时间: 2023-06-08 09:04:55 浏览: 178
sql语句获取数据库中的数据库表列.docx
1. SELECT d.ID AS "部门ID", d.Name AS "部门名称", COUNT(e.ID) AS "员工数量"
FROM departments d
LEFT JOIN Employees e ON d.ID = e.Departmentld
GROUP BY d.ID, d.Name
HAVING COUNT(e.ID) >= 10;
2. SELECT e1.ID AS "员工ID", e1.Code AS "员工Code", e1.Name AS "员工姓名"
FROM Employees e1
JOIN (SELECT Code, COUNT(*) as count FROM Employees GROUP BY Code HAVING COUNT(*) > 1) e2
ON e1.Code = e2.Code;
3. SELECT e.ID AS "员工ID", e.Name AS "员工名称", d.Name AS "部门名称"
FROM Employees e
LEFT JOIN departments d ON e.Departmentld = d.ID
ORDER BY e.ID ASC;
阅读全文