求几句简单的SQL语句,小弟小白一个~!真的是简单的!

qq576420473 2013-04-24 05:51:28
有三张表:
学生表studet
Sno学号 Sname姓名 Ssex性别 Sage年龄 ClassNo班级
课程表course
Cno课程号 Cname课程名称 Credit学分 Tno教师代号
成绩表SC
Sno 学号 Cno课程号 Grade成绩 Date考试时间
教师表teacher
Tno教师号 Tname姓名 Ssex性别 Sage年龄

问题1
查考试成绩有不及格的学生的学号和姓名,且消除重复行

问题2
查询至少选修一门“李峰”老师的课程的学生姓名

问题3
检索出没有被任何学生选修的课程

问题4
求出少于10个学生选修的课程

问题5
求出有四门课程考试不及格的学生的学生号、姓名

问题6
求出教了三门课程以上的老师

问题7
求出每一个班级中每一门课程获得最高分的学生的学号与姓名

...全文
285 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
超凡 2013-04-26
  • 打赏
  • 举报
回复
引用 楼主 qq576420473 的回复:
有三张表: 学生表studet Sno学号 Sname姓名 Ssex性别 Sage年龄 ClassNo班级 课程表course Cno课程号 Cname课程名称 Credit学分 Tno教师代号 成绩表SC Sno 学号 Cno课程号 Grade成绩 Date考试时间 教师表teacher Tno教师号 Tname姓名 Ssex性别……
楼主偷懒啊!
daiyueqiang2045 2013-04-26
  • 打赏
  • 举报
回复
引用 3 楼 qq7278449 的回复:
帮你做了前4题 如果是考试应该及格了 都是上机亲测的答案! 1 select distinct student.Sno,student.Sname from student,SC where student.Sno=SC.Sno and SC.Grade<60 2 select distinct student.Sname from student,course,SC,teacher where student.Sno=SC.Sno and course.Cno=SC.Cno and course.Tno=teacher.Tno and teacher.Tname='李峰' 3 select distinct course.Cname from course,SC where course.Cno not in (select distinct SC.Cno from SC) 4 select course.Cname from course where course.Cno in (select SC.Cno from SC group by SC.Cno having count(*)<10) or course.Cno not in (select distinct SC.Cno from SC) 希望你自己能把其余三道题 通过自己的学习做出来。作为一名程序员最起码的学习能力应该有。
qq576420473 2013-04-26
  • 打赏
  • 举报
回复
引用 3 楼 qq7278449 的回复:
帮你做了前4题 如果是考试应该及格了 都是上机亲测的答案! 1 select distinct student.Sno,student.Sname from student,SC where student.Sno=SC.Sno and SC.Grade<60 2 select distinct student.Sname from student,course,SC,teacher where student.Sno=SC.Sno and course.Cno=SC.Cno and course.Tno=teacher.Tno and teacher.Tname='李峰' 3 select distinct course.Cname from course,SC where course.Cno not in (select distinct SC.Cno from SC) 4 select course.Cname from course where course.Cno in (select SC.Cno from SC group by SC.Cno having count(*)<10) or course.Cno not in (select distinct SC.Cno from SC) 希望你自己能把其余三道题 通过自己的学习做出来。作为一名程序员最起码的学习能力应该有。
这位童鞋很好
qq576420473 2013-04-26
  • 打赏
  • 举报
回复
引用 9 楼 hncelfhv 的回复:
[quote=引用 楼主 qq576420473 的回复:] 有三张表: 学生表studet Sno学号 Sname姓名 Ssex性别 Sage年龄 ClassNo班级 课程表course Cno课程号 Cname课程名称 Credit学分 Tno教师代号 成绩表SC Sno 学号 Cno课程号 Grade成绩 Date考试时间 教师表teacher Tno教师号 Tname姓名 Ssex性别……
楼主偷懒啊! [/quote] 没办法,每天都要做任务
qq576420473 2013-04-26
  • 打赏
  • 举报
回复
引用 8 楼 Live_eviL 的回复:
典型的作业题,这种我觉得大家就没必要帮了吧。
大哥,给点面子呀
连星入剑端 2013-04-25
  • 打赏
  • 举报
回复
典型的作业题,这种我觉得大家就没必要帮了吧。
heli_1005 2013-04-25
  • 打赏
  • 举报
回复
1.select distinct sno,sname from student st where exists( select 1 from sc where sno=st.sno and grade<60) 2. select sname from student st where exists( select 1 from sc join course on sc.sno=st.sno and sc.cno=course.cno join teacher on course.tno=teacher.tno and teacher.name='李峰') 3. select cname from course left join sc on course.cno=sc.cno and sc.cno is null4. select cno from sc group by cno having count(1)<10 5. select sno,sname from student where exists ( select 1 from sc where sno=st.sno and grade<60 )group by sno,sname having count(1)=4 6. select tno,tname from teacher te join( select tno from course group by tno having COUNT(1)>3 )t on tempdb.tno=t.tno
zhengnan2012 2013-04-25
  • 打赏
  • 举报
回复
问题1 查考试成绩有不及格的学生的学号和姓名,且消除重复行 SELECT DISTINCT b.sno,b.sname FROM sc a JOIN student b ON a.sno=b.sno WHERE a.grade<60 问题2 查询至少选修一门“李峰”老师的课程的学生姓名 -- 少了一个 选课表 ,难道你叫我通过成绩表来查选课?这不科学 问题3 检索出没有被任何学生选修的课程 -- 少了一个 选课表 ,难道你叫我通过成绩表来查选课?这不科学 问题4 求出少于10个学生选修的课程 -- 少了一个 选课表 ,难道你叫我通过成绩表来查选课?这不科学 问题5 求出有四门课程考试不及格的学生的学生号、姓名 SELECT b.sno,b.sname FROM sc a JOIN student b ON a.sno=b.sno GROUP BY a.sno,b.sname HAVING(SUM(CASE WHEN grade<60 THEN 1 ELSE 0 END ))>=4 问题6 求出教了三门课程以上的老师 -- 少了一个 选课表 问题7 求出每一个班级中每一门课程获得最高分的学生的学号与姓名 SELECT w.sno,w.sname FROM (SELECT a.sno,a.sname,a.classno,b.cno FROM student a JOIN sc b ON a.sno=b.sno) w JOIN ( SELECT a.classno,b.cno,MAX(grade) FROM student a JOIN sc b ON a.sno=b.sno GROUP BY a.classno,b.cno ) v ON w.classno=v.classno AND w.cno AND b.cno
daiyueqiang2045 2013-04-25
  • 打赏
  • 举报
回复
lz 这要是交作业哦 呵呵
习惯性蹭分 2013-04-25
  • 打赏
  • 举报
回复

1.select distinct sno,sname from student st where exists(
select 1 from sc where sno=st.sno and grade<60)
2. select sname from student st where exists(
select 1 from sc join course on sc.sno=st.sno and sc.cno=course.cno
join teacher on course.tno=teacher.tno and teacher.name='李峰'
)
3. select cname from course left join sc on course.cno=sc.cno and sc.cno is null
4. select cno from sc group by cno having count(1)<10
5. select sno,sname from student where exists (
select 1 from sc where sno=st.sno and grade<60
)group by sno,sname having count(1)=4
6. select tno,tname from teacher te join(
select tno from course group by tno having COUNT(1)>3
)t on tempdb.tno=t.tno
)
哈尔滨--猫猫 2013-04-24
  • 打赏
  • 举报
回复
帮你做了前4题 如果是考试应该及格了 都是上机亲测的答案!
1 select distinct student.Sno,student.Sname from student,SC where student.Sno=SC.Sno and SC.Grade<60
2 select distinct student.Sname from student,course,SC,teacher
where student.Sno=SC.Sno and
course.Cno=SC.Cno and
course.Tno=teacher.Tno and
teacher.Tname='李峰'
3 select distinct course.Cname from course,SC
where course.Cno not in (select distinct SC.Cno from SC)
4 select course.Cname from course where course.Cno in
(select SC.Cno from SC group by SC.Cno having count(*)<10) or
course.Cno not in (select distinct SC.Cno from SC)

希望你自己能把其余三道题 通过自己的学习做出来。作为一名程序员最起码的学习能力应该有。
叶子 2013-04-24
  • 打赏
  • 举报
回复
MrYangkang 2013-04-24
  • 打赏
  • 举报
回复
查询至少选修一门“李峰”老师的课程的学生姓名 select distinct Student.* from Student , SC , Course , Teacher where Student.S# = SC.S# and SC.C# = Course.C# and Course.T# = Teacher.T# and Teacher.Tname = N'李峰' order by Student.S#

34,588

社区成员

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

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