数据库.查询语句
2015-07-24 23:56
169 查看
[code]2)查询T_STUDENT中所有的数据 select * from T_student; 3)查询T_STUDENT中所有学生的姓名和性别 select stuname,stusex from T_student; 4)将学号和姓名显示,其中,姓名的格式为:“姓名:xxx” select '姓名:'||stuname as " ",stuno from T_student; 5)为了更好地体现各个学生的考试情况,将T_SCORE中的信息显示,分数显示为与60分的差。 select stuno,courseno,type,score-60 from T_score; 6) 将T_SCORE中的信息显示,分数显示为与60分的差值,列名为“差值”,如果第一条记录分数为空,会得出来什么结果。 (注意:空值具有特殊性,包括空值的任何算术表达式都等于空) select stuno,courseno,type,score-60 as 差值 from T_score; 7) 将学号和姓名显示,其中,列名分别显示为“学生”和姓名。 select stuno as 学号,stuname as 姓名 from T_student; 8) 将学号和姓名显示在一个列中,列名显示为:信息。 select stuno 信息 from T_student union select stuname from T_student; 9) 查询教师的职称种类 select count(distinct teatitle) from T_teacher; 10) 查询女生的姓名 select stuname from T_student where stusex='女'; 11) 查询课程VB的信息 select * from T_course where coursename='VB'; 12) 显示所有期中考试及格的记录 select * from T_score where type='期中'and score>=60; 13) 为了找出考试尖子,需要显示所有期末考试在90-100的考试记录(使用<,> between and) select * from T_score where score>90 and score<=100 and type='期末'; select * from T_score where score between '90'and '100' and type='期末'; 14) 学校要举行一帮一活动,让高分学生帮助低分学生。查询90分以上的期末考试记录,以及不及格的期末考试记录 select * from T_score where (score>90 or score<60) and type='期末' ; 15) 利用BETWEEN谓词显示所有期末考试在65-80的考试记录 select * from T_score where (score between '65' and '85') and type='期末'; 16) 使用IN谓词,显示分数是60,70,80的考试记录 select * from T_score where score in (60,70,80) order by score DESC--降序 ; 17) 查询姓李的学生资料 select * from T_student where stuname like '王%'; 18) 查询姓“王”,名字为一个字的学生,并将这类学生的详细信息显示出来 select * from T_student where stuname like '王_'; 19) 查询性别为空的学生资料 select * from T_student where stusex is NULL; 20) 用升序显示学生S001的所有期末考试成绩 select score from T_score where stuno='S001'and type='期末' order by score--默认为升序; 21) 用降序显示课程C001的所有期末考试成绩,对于相等的成绩,则按照课程编号升序显示。 select courseno,score from T_score where courseno='C001' and type='期末' order by score DESC; 22) 查询姓名为“郭莉芳”的考试成绩 select* from T_score where stuno=( select stuno from T_student where stuname='郭莉芳' ); 23) 显示各个教师及其讲授课程的详细情况 select T_teacher.teaname,T_course.*(这两个顺序有关) from T_teacher right join T_course on T_teacher.teano=T_course.teano; 24) 查询名为“梁天”的教师没有上过的课程。 select coursename from T_course where not exists( select * from T_teacher where T_course.teano=T_teacher.teano and teaname='梁天' ); 25) 课程“大学物理”,有哪些学生选过?请列出这些学生的姓名 select stuname from T_student where stuno=( select stuno from T_score where courseno=( select courseno from T_course where coursename='大学物理' ) ); 26) 查询学号为”S002”的学生,参加课程“C001”考试的成绩,显示格式为: 期中成绩 期末成绩 总评成绩 其中,总评成绩=期中成绩*0.4+期末成绩*0.6 select x.score as 期中成绩,y.score as 期末成绩,x.score*0.4+y.score*0.6 as 总评成绩 from T_score x ,T_score y where x.stuno='S002' and y.stuno='S002'and x.type='期中' and y.type='期末' and x.courseno='C001' and y.courseno='C001'; 27) 查询课程“大学物理”是哪一位老师教的,列出其姓名 select T_teacher.teaname,T_course.coursename from T_teacher ,T_course where T_teacher.teano in ( select teano from T_course where coursename='大学物理') and T_course.coursename='大学物理'; 28) 使用左外连接完成27) select T_teacher.teaname,T_course.coursename from T_teacher left join T_course on T_teacher.teano in ( select teano from T_course where coursename='大学物理') and T_course.coursename='大学物理'; 29) 使用右外连接完成27) select T_teacher.teaname,T_course.coursename from T_teacher right join T_course on T_teacher.teano in ( select teano from T_course where coursename='大学物理') and T_course.coursename='大学物理'; 30) 查询T_STUDENT内所有人的姓名和性别 select stuname,stusex from T_student; 31) 将学号和姓名用下划线连接,显示在一列。 select stuname||'_'||stuno as " " from T_student; 32) 显示教授的所有资料 select * from T_teacher,T_course where T_teacher.teatitle='教授' and T_teacher.teano=T_course.teano; 33) 显示姓张的男生的姓名 select stuname from T_student where stuname like '王%'; 34) 将所有的分数显示为与60分的差值,同时也显示原分数。 select score,score-60 as 与60分的差值 from T_score; 35) 查询高级职称以下的教师姓名,高级职称以下为副教授和讲师 select teaname,teatitle from T_teacher where teatitle in ('副教授','讲师') order by teatitle; 36) 学校需要请学生对教授的教学作评价,因此需要通知相关学生。请查询出:教授所教过的课程,有哪些学生选过?列出他们的姓名 select distinct T_teacher.teaname, T_student.stuname,T_course.coursename from T_teacher,T_student,T_course,T_score where T_teacher.teatitle='教授' and T_teacher.teano=T_course.teano and T_score.courseno=T_course.courseno and T_score.stuno=T_student.stuno order by T_teacher.teaname; 37) 查询郭莉芳的哪些科目期末考试没有及格?列出这些科目的名称和分数 select T_course.coursename,T_score.score from T_course,T_score,T_student where T_student.stuname='郭莉芳' and T_score.score<60 and T_course.courseno=T_score.courseno and T_student.stuno=T_score.stuno and T_score.type='期末'; 38) 统计学生姓名的数量 select count(stuname) from T_student; 39) 查询学校有多少名教师 select count(teaname) from T_teacher; 40) 查询为“梁天”的教师讲了多少门课 select count(teano) from T_course where teano=( select teano from T_teacher where teaname='梁天' ); 41) 查询参加过考试的学生数量 select count(distinct stuno) from T_score; 42) 查询郭莉芳选了多少门课 select count(distinct T_score.courseno) as 郭莉芳选课门数 from T_score,T_student where T_score.stuno=T_student.stuno and T_student.stuname='郭莉芳'; 43) 查询课程C002的期末考试平均分 select ***G(T_score.score) as 课程C002的期末考试平均分 from T_score,T_course where T_course.courseno=T_score.courseno and T_course.courseno='C002' and T_score.type='期末'; 44) 查询课程C003的期中考试总分 select SUM(distinct T_score.score) as 课程C003的期中考试总分 from T_score,T_course where T_course.courseno=T_score.courseno and T_course.courseno='C003' and T_score.type='期中'; 45) 查询学校所有考试记录的总分 select sum(score) from T_score; 46) 查询课程C004的期末考试最高分 select max(T_score.score) from T_score,T_course where T_score.type='期末' and T_score.courseno=T_course.courseno and T_course.courseno='C004'; 47) 查询每个教师讲授的课程数量,并将其姓名和课程数量显示出来 select T_teacher.teaname as 教师,count(T_course.teano) as 课程数量 from T_teacher left join T_course on T_teacher.teano=T_course.teano group by T_teacher.teaname; 48) 查询郭莉芳每门课的平均分,显示课程名称和平均分 select T_course.coursename as 课程,***G(T_score.score) as 平均分 from T_course,T_score,T_student where T_student.stuno=T_score.stuno and T_score.courseno=T_course.courseno and T_student.stuname='郭莉芳' group by T_course.coursename; 49) 学校要查询哪门课的授课效果最好,请查询各门课程平均分的最大值 做法1: select ***G(T_score.score) as 各门课程平均分的最大值 from T_score,T_course where T_score.courseno in (select courseno from(select courseno,***G(score), rank()over(order by avg(score) desc)k from T_score group by courseno) where k=1); 做法2: select max(avg(score)) as 各门课程平均分的最大值 from T_score group by courseno having avg(score) in (select avg(score) from T_score group by courseno );
相关文章推荐
- SQL 事务
- 数据库.创建表
- MySQL出现“错误1067:进程意外终止”
- MySQL出现“错误1067:进程意外终止”
- Navicat for MySQL数据库管理工具
- 程序猿利器(二) sql server 存储过程升级脚本自动合并
- 小贝_mysql sql语句优化过程
- 小贝_mysql优化学习
- 开发-数据库-MongoDB初探
- 数据库设计问题解决
- SQL中数据定义语言(DDL)、数据操纵语言(DML)、数据控制语言(DCL)
- MYsql的length的函数 strim
- mysql中文乱码,修改配置为utf-8
- NoSQL 数据建模技术
- Oracle EBS(ERP)行业分工(写给猎头)
- Using MySQL as a NoSQL
- 详解NoSQL数据库使用实例
- Django1.8 更新数据库
- 解决MySQL 一闪而过的情况
- win7下Qt5使用mysql C++编程配置