首页 > 数据库技术 > 详细

Day44 数据库的操作

时间:2018-04-07 16:57:48      阅读:232      评论:0      收藏:0      [点我收藏+]

一 、 多表操作

select * from person,dept

技术分享图片

 

二 、多表联合操作 

 select * from person,dept where person.dept_id =dept.did   

技术分享图片

 

 

 

 

select * from person,dept where person.dept_id =dept.did and person.salary >3000

 

 

三、多表连接查询

左连接查询 (以左表作为基准)

select *from person left JOIN dept  on person.dept_id = dept.did

 技术分享图片

 

内连接查询 

 select * from person inner JOIN dept where  person.dept_id =dept.did

技术分享图片

 

 

4.全连接查询 full JOIN
select * from person LEFT JOIN dept ON person.dept_id = dept.did
UNION ALL
select * from person RIGHT JOIN dept on person.dept_id = dept.did;

 

二 、 复杂的多表查询  。 

 

1. 查询出 教学部 年龄大于20岁,并且工资小于40000的员工,按工资倒序排列.(要求:分别使用多表联合查询和内连接查询)

 

 select * from person inner join dept on person.dept_id = dept.did and dept.dname = ‘教学部‘ and person.age >20 and salary <40000 order by person.salary asc

技术分享图片

 

Day44 数据库的操作

原文:https://www.cnblogs.com/mengbin0546/p/8733454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!