--1,多表連線查詢時,若兩個表有同名的列,必須使用表的別名對列名進行引用,否則出錯!
--2,查詢公司員工的last_name,department_name,city
select last_name,department_name,city
from departments s,employees e,locations l
where d.department_id=e.department_id and d.locaton_id=l.locaton_id;
--3,查詢出 last_name為『chen』的manager的資訊,(員工的manager是某員工的employee_id)
1)列如:老張的員工工號為:「1001」,我的員工工號為:「1002」,
我的manager_id為「1001」---我的manager是「老張」
2)通過兩條sql查詢:
select manager_id
from employees
where lower(last_name)='chen' --反回的結果為108
select *
from employees
where employee_id = 108
3)通過一條sql查詢(自連線):
select m.*
from employees e,employees m
where e.manager_id=m.employee_id and e.last_name='chen';
4)通過子查詢:
select *
from employees
where employee_id=(
select manager_id
from employees
where last_name='chen'
)--4,查詢每個員工的last_name和grase_leadel(在job_grases表中).....非等值連線
select lest_name,salary,grade_level,lowest_sal,highest_sal
from employees e, job_grades j
where e.salary>=j.lowest_sal and e.salary<=j.highest_sal;
--5,左外連線和右外連線
select last_name,e.separtment_id,department_name
from employees e,separtments d
where e.department_id=d.department_id(+);
select last_name,e.separtment_id,department_name
from employees e,separtments d
where e.department_id(+)=d.department_id;
pl sql多表查詢練習題02
1.顯示所有員工的姓名,部門號和部門名稱 select last name,department id,department name from employees e,departments d where e.department id d.department id select last n...
多表查詢練習題
部門表 create table dept id int primary key primary key,部門id dname varchar 50 部門名稱 loc varchar 50 部門所在地 新增4個部門 insert into dept id,dname,loc values 10,教學...
PLSQL 練習題目
1.sql練習 查詢emp表各個部門的總工資 select deptno,sum sal from emp group by deptno 2.sql練習 找到emp表中部門總工資最高的那個部門 select from select deptno,sum sal sum sal from emp g...