首页 小组 文章 相册 留言本 用户 搜索 我的社区 在线学堂 商城 购物车 支付钱包

kk.多表查询

2024-04-10 15:16:10
0
158

SELECT employee_id,last_name,department_name,city
FROM employees e,departments d, locations l
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id;
#非等值连接
SELECT * FROM job_grades;

#查询名字、月薪、和对应的等级

SELECT e.last_name,e.salary,j.grade_level
FROM employees e,job_grades j
WHERE e.salary BETWEEN j.lowest_sal AND j.highest_sal;

SELECT * FROM employees;

SELECT e.last_name,e.salary,j.grade_level
FROM employees e,job_grades j
WHERE e.salary >= j.lowest_sal AND e.salary<=j.highest_sal;

#角度2:自连接(自我引用)vs非自连接

SELECT * FROM employees;

#练习:查询员工id,员工姓名及其管理者的id和姓名

SELECT emp.employee_id,emp.last_name,mgr.employee_id,mgr.last_name
FROM employees emp,employees mgr
where emp.manager_id=mgr.employee_id;
















评论
意见反馈