首页 > 数据库技术 > 详细

2020/3/25 下午 数据库第四章 自连接

时间:2020-07-05 17:26:02      阅读:43      评论:0      收藏:0      [点我收藏+]

自连接  

查询与“数据结构”学分相同的课程的课程名和学分

SELECT C2.Cname,C1.Credit

FROM Course C1 JOIN Course C2

ON C1.credit=C2.credit

where C2.Cname=‘数据结构‘

and C2.Cname!=‘数据结构‘

外连接

查询学生的选课情况,包括选了课程的学生和没有选课程的学生

SELECT Student.Sno,Sname,Cno,Grade

FROM Student left join SC

on Student.Sno=SC.Sno

SELECT STUDENT.sno,Sname,Cno,Grade

FROM SC right join Student

on Student.Sno=SC.Sno

查询哪些课程没有人选,列出其课程名

SELECT Cname from Couse C left join SC

on C.Cno=SC.Cno

where SC.cno IS null

with ties

select top 3 with ties Sname,Sdept,Grade

from Student S join SC on S.Sno=SC.Sno

where Cname=‘Java‘

Order by Grade DESC

select sno,sname,sdept from Student

where sdept in (

select sdept from Student where sname=‘刘晨‘

select S2.Sname from Student S1 Join Student S2

on S1.Sdept=S2.sdept

where S1.Sname=‘l刘晨‘

2020/3/25 下午 数据库第四章 自连接

原文:https://www.cnblogs.com/Stephen-wife/p/12566658.html

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