mysql 查询语句学生表、课程表、 成绩表、教师表mysql 查询语句学生表、课程表、 成绩表、教师表.docx

mysql 查询语句学生表、课程表、 成绩表、教师表mysql 查询语句学生表、课程表、 成绩表、教师表.docx

  1. 1、本文档共24页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
mysql 查询语句学生表、课程表、 成绩表、教师表mysql 查询语句学生表、课程表、 成绩表、教师表

【引用】学生表、课程表、 成绩表、教师表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??006create table Student(S# varchar(20),Sname varchar(10),Sage int,Ssex varchar(2))? 007--前面加一列序号: 008if 009exists(select table_name from information_schema.tables 010?where table_name=Temp_Table) 011drop table Temp_Table 012go 013select 排名=identity(int,1,1),* INTO Temp_Tablefrom Student? 014go 015select * from Temp_Table 016go? 017??018drop 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.scoreb.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 Student043?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# and SC.C#=001and exists( Select * from SC as SC_2 where SC_2.S#=SC.S# and SC_2.C#=002);? 047??048--7、查询学过“叶平”老师所教的所有课的同学的学号、姓名; 049?select S#,Sname? 050?from Student? 051?where S# in (select S# from SC ,Course ,Teacher where SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname=叶平 group by S# having count(SC.C#)=(select count(C#) from Course,Teacher? where Teacher.T#=Course.T# and Tname=叶平));? 052??053--8、查询课程编号“”的成绩比课程编号“”课程低的所有同学的学号、姓名; 05

您可能关注的文档

文档评论(0)

vshoulrengb3 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档