电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

mysql查询语句学生表、课程表、成绩表、教师表VIP免费

mysql查询语句学生表、课程表、成绩表、教师表_第1页
mysql查询语句学生表、课程表、成绩表、教师表_第2页
mysql查询语句学生表、课程表、成绩表、教师表_第3页
【引用】学生表、课程表、 成绩表、教师表50 个常用sql 语句 2011-08-07 15:01:48| 分类: 数据库 | 标签: |字号大中小 订阅 本文引用自大河之舟《学生表、课程表、 成绩表、教师表50 个常用sql 语句》 001 --Student(S#,Sname,Sage,Ssex) -- 学生表 002 --Course(C#,Cname,T#) --课程表 003 --SC(S#,C#,score) --成绩表 004 --Teacher(T#,Tname) --教师表 005 006 create table Student(S# varchar(20),Sname varchar(10),Sage int,Ssex varchar(2)) 007 --前面加一列序号: 008 if 009 exists(select table_name from information_schema.tables 010 where table_name='Temp_Table') 011 drop table Temp_Table 012 go 013 select 排名=identity(int,1,1),* INTO Temp_Table from Student 014 go 015 select * from Temp_Table 016 go 017 018 drop database [ ] --删除空的没有名字的数据库 019 --问题: 020 --1、查询“”课程比“”课程成绩高的所有学生的学号; 021 select a.S# from (select s#,score from SC where C#='001') a,(select s#,score 022 from SC where C#='002') b 023 where a.score>b.score and a.s#=b.s#; 024 025 --2、查询平均成绩大于分的同学的学号和平均成绩; 026 select S#,avg(score) 027 from sc 028 group by S# having avg(score) >60; 029 030 --3、查询所有同学的学号、姓名、选课数、总成绩; 031 select Student.S#,Student.Sname,count(SC.C#),sum(score) 032 from Student left Outer join SC on Student.S#=SC.S# 033 group by Student.S#,Sname 034 035 --4、查询姓“李”的老师的个数; 036 select count(distinct(Tname)) 037 from Teacher 038 where Tname like '李%'; 039 040 --5、查询没学过“叶平”老师课的同学的学号、姓名; 041 select Student.S#,Student.Sname 042 from Student 043 where S# not in (select distinct( SC.S#) from SC,Course,Teacher where SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname='叶平'); 044 045 --6、查询学过“”并且也学过编号“”课程的同学的学号、姓名; 046 select Student.S#,Student.Sname from Student,SC where Student.S#=SC.S#...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部