-- 1.查询所有员工信息。查询员工编号,员工姓名,工资,职务名称,职务描述
SELECT
emp.id,emp.`salary`,
job.`jname`,job.`description`
FROM
emp,job
WHERE
emp.`job_id`=job.`id`;
-- 2.查询员工编号,员工姓名,工资,职务名称,职务描述,部门名称,部门位置
SELECT
emp.id,emp.`ename`,emp.`salary`,
job.`jname`,job.`description`,
dept.`dname`,dept.`loc`
FROM
emp,job,dept
WHERE
emp.`job_id`=job.`id`
AND
emp.`dept_id`=dept.`id`;
-- 3.查询员工姓名,工资,工资等级
SELECT
emp.`ename`,emp.`salary`,t2.`grade`
FROM
emp,salarygrade t2
WHERE
emp.`salary` BETWEEN t2.`losalary` AND t2.`hisalary`;
-- 4.查询员工姓名,工资,职务名称,职务描述,部门名称,部门位置,工资等级
SELECT
emp.`ename`,emp.`salary`,job.`jname`,job.`description`,dept.`dname`,dept.`loc`,salg.`grade`
FROM
emp,job,dept,salarygrade salg
WHERE
emp.`job_id`=job.`id` AND emp.`dept_id`=dept.`id` AND emp.`salary` BETWEEN salg.`losalary` AND salg.`hisalary`;
-- 5.查询出部门编号、部门名称、部门位置、部门人数
SELECT
dept.`id`,dept.`dname`,dept.`loc`,em.total
FROM
dept,(SELECT emp.`dept_id` ,COUNT(id) total FROM emp GROUP BY emp.`dept_id`) em
WHERE
dept.`id`=em.dept_id;
-- 6.查询所有员工的姓名及其直接上级的姓名,没有领导的员工也需要查询
SELECT
t1.`ename`,t2.ename
FROM
emp t1
LEFT JOIN
emp t2
ON
t1.`mgr`=t2.id;
|
|