一个简单的SQL语句,送分的,多谢了!

dawnhorizon 2003-03-11 02:52:41
已知关系模式:
Student(S#学号,Sname姓名,Ssex性别,Sage年龄,Sdept系),S#为主关键字;
Course(C#课程编号,Cname课程名,Ccredit学分),C#为主关键字;
Sc(S#学号,C#课号,Grade成绩),S#与C#的属性组合为主关键字。
查询Sdept为本系选修了3门以上课程的学生学号,请分别用嵌套查询和连接查询给出答案。

本人刚开始学习SQL,很多地方还不熟,多谢热心人了!
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
happydreamer 2003-03-11
  • 打赏
  • 举报
回复
select a.S#
from sc a join student b on a.s#=b.s#
where b.sdept='本系' and (select count(c#) from sc where s#=a.s#)>=3
yoki 2003-03-11
  • 打赏
  • 举报
回复
select s#
from student a
where sdept='系名' and a.s# in
(
select b.s# from sc b group by b.s# having count(*)>=3
)
愉快的登山者 2003-03-11
  • 打赏
  • 举报
回复
1。嵌套查询:
select A.S# from Sc as A, Student as B
where B.Sdept = ‘本系’
and A.S# = B.S#
and (select count(*) from Sc where S# = A.S#) >= 3
order by A.S#
2。连接查询:
select A.S# from Sc as A left join Student as B
on A.S# = B.S#
where B.Sdept = ‘本系’
and (select count(*) from Sc where S# = A.S#) >= 3
order by A.S#
pengdali 2003-03-11
  • 打赏
  • 举报
回复
select s# from sc group by s# having count(*)>=3

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧