练习
1.写一个查询显示所有雇员的 last name、department id、anddepartment name。
mysql">SELECT
e.LAST_NAME,e.DEPARTMENT_ID,d.DEPARTMENT_NAME
FROM employees e,departments d
WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID;
2.创建一个在部门 80 中的所有工作岗位的唯一列表,在输出中包括部门的地点。
mysql">SELECT DISTINCT
e.JOB_ID,d.LOCATION_ID
FROM employees e,departments d
WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID
AND e.DEPARTMENT_ID = 80;
3.写一个查询显示所有有佣金的雇员的 last name、departmentname、location ID 和城市
mysql">SELECT
e.LAST_NAME,d.DEPARTMENT_NAME,d.LOCATION_ID,l.CITY
FROM employees e,departments d,locations l
WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID
AND d.LOCATION_ID = l.LOCATION_ID
AND e.COMMISSION_PCT is not null;
4.显示所有在其 last names 中有一个小写 a 的雇员的 last name 和departmentname。
mysql">select
e.LAST_NAME,d.DEPARTMENT_NAME
FROM employees e,departments d
where e.DEPARTMENT_ID = d.DEPARTMENT_ID
AND e.LAST_NAME like '%a%';
5.用sql99的内连接写一个查询显示那些工作在 Toronto 的所有雇员的 last name、job、department number 和 departmentname。
mysql">SELECT
e.LAST_NAME,e.JOB_ID,e.DEPARTMENT_ID,d.DEPARTMENT_NAME
WHERE l.CITY = 'Toronto';
6.显示雇员的 last name 和 employee number 连同他们的经理的last name 和manager number。列标签分别为 Employee、Emp#、Manager 和 Mgr#
mysql">SELECT
w.LAST_NAME empname,w.DEPARTMENT_ID
empid,m.LAST_NAME mgrname,m.EMPLOYEE_ID mgrid
FROM employees w INNER JOIN employees m
ON w.MANAGER_ID = m.EMPLOYEE_ID;