/*student(学号#,姓名,性别,年龄)
course(课程号#,课程名,教师号#)
score(学号#,课程号#,成绩)
teacher(教师号#,教师名)*/  --1.查询“001”课程比“002”课程成绩高的所有学生的学号
select a.stuNo from score a,score b
where a.cNo='c001' and b.cNo='c002' and a.stuNo=b.stuNo and a.score>b.score
--2.查询平均成绩大于60分的同学的学号和平均成绩
select stuNo,avg(score)from score
group by stuNo
having avg(score)>60
--3.查询所有同学的学号、姓名、选课数、总成绩
select a.stuNo,a.stuName,count(cNo),sum(score) from student a,score b
where a.stuNo=b.stuNo
group by a.stuNo,a.stuName
--4.查询姓“赵”的老师的个数
select count(tName),tName from teacher
where tName like '赵%'
group by tName
--5.查询没学过“某某”老师课的同学的学号、姓名
select stuNo,stuName from student
where stuNo not in
(select a.stuNo from student a,score b where a.stuNo=b.stuNo and cNo in
(select d.cNo from teacher c,course d where c.tNo=d.tNo and c.tName='钱市保'))
--6.查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
select a.stuNo,a.stuName from student a,score b,score c
where a.stuNo=b.stuNo and b.stuNo=c.stuNo and b.cNo='c001' and c.cNo='c002'
--7.查询学过“某某”老师所教的所有课的同学的学号、姓名
select stuNo,stuName from student
where stuNo in (select stuNo from score a,course b,teacher c
where a.cNo=b.cNo and b.tNo=c.tNo and c.tName='钱市保'
group by stuNo
having count(a.cNo)>=(select count(cNo) from course d,teacher e
where d.tNo=e.tNo and e.tName='钱市保'))
--老师所教课程为一门课
select stuNo,stuName from student
where stuNo in (select a.stuNo from student a,score b where a.stuNo=b.stuNo and b.cNo in
(select cNo from teacher c,course d where c.tNo=d.tNo and c.tName='钱市保'))
--8.查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名
select stuNo,stuName from student
where stuNo in
(select a.stuNo from score a,score b
where a.cNo='c001' and b.cNo='c002' and a.stuNo=b.stuNo and a.score>b.score)
--9.查询所有课程成绩小于60分的同学的学号、姓名
select stuNo,stuName from student
where stuNo in (select stuNo from score
where score<60
group by stuNo
having count(cNo)=(select count(cNo) from course))
--10.查询没有学全所有课的同学的学号、姓名
select b.stuNo,a.stuName,count(b.cNo) from student a,score b
where a.stuNo=b.stuNo
group by b.stuNo,a.stuName
having count(b.cNo)<(select count(cNo) from course)
--11.查询至少有一门课与学号为“1”的同学所学相同的同学的学号和姓名
select distinct a.stuNo,stuName from student a,score b
where a.stuNo=b.stuNo and cNo in (select cNo from score
where stuNo='001')
--12.查询至少学过学号为“001”同学一门课的其他同学学号和姓名
&&& select distinct a.stuNo,stuName from student a,score b
where a.stuNo=b.stuNo and cNo all join (select cNo from score
where stuNo='001')
--13.把“SC”表中“某某”老师教的课的成绩都更改为此课程的平均成绩
update score set score=savg
from score d,(select avg(score) as savg,a.cNo from score a,course b,teacher c
where a.cNo=b.cNo and b.tNo=c.tNo and tName='钱市保'
group by a.cNo) e
where d.cNo=e.cNo
--老师所教课程为一门课
update score
set score=(select avg(score) from score
group by cNo
having cNo=(select a.cNo from course a,teacher b where a.tNo=b.tNo and b.tName='钱市保'))
where cNo=(select a.cNo from course a,teacher b where a.tNo=b.tNo and b.tName='钱市保')
select * from score
--14.查询和“001”号的同学学习的课程完全相同的其他同学学号和姓名
select stuNo from score
where cNo in (select cNo from score where stuNo='005')
group by stuNo
having count(cNo)=(select count(*) from score where stuNo='005')
--15.删除学习“某某”老师课的SC表记录
delete from score where cNo=(select cNo from course a,teacher b where a.tNo=b.tNo and b.tName='钱市保')
select * from score
--16.向SC表中插入一些记录,这些记录要求符合以下条件:没有上过编号“003”课程的同学学号、2号课的平均成绩
--17.按平均成绩从高到低显示所有学生的“C语言”、“sql”、“java”三门的课程成绩
--按如下形式显示: 学生ID,C语言,sql,JAVA,有效课程数,有效平均分
--18.查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分
select  cNo,max(score) as 最高分,min(score) as 最低分 from score
group by cNo
--19.按各科平均成绩从低到高和及格率的百分数从高到低顺序
select avg(c.score),count(a.score)/count(b.score) from score c,(select a.cNo,count(a.score) from score a
where a.score<60
group by a.cNo) d,(select b.cNo,count(b.score) from score b
group by b.cNo) e
where d.cNo=e.cNo
group by c.cNo
order by avg(c.score) desc
(select a.cNo,count(a.score) from score a
where a.score<60
group by a.cNo) d
(select b.cNo,count(b.score) from score b
group by b.cNo) e
--20.查询如下课程平均成绩和及格率的百分数(用"1行"显示): C语言(001),数据结构(002),JAVA(003),离散数学(004)
--21.查询不同老师所教不同课程平均分从高到低显示
select tNo,a.cNo,avg(score) from course a,score b
where a.cNo=b.cNo
group by tNo,a.cNo
order by avg(score) desc
--22.查询如下课程成绩第 3 名到第 6 名的学生成绩单:C语言(001),数据结构(002),JAVA(003),离散数学(004)
--   [学生ID],[学生姓名],C语言,数据结构,JAVA,离散数学,平均成绩
--23.统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60]
select distinct e.cNo,count(a.stuNo) as '100-85',count(b.stuNo) as '85-70',count(c.stuNo) as '70-60',count(d.stuNo) as '<60' from score a,score b,score c,score d,score e
where a.cNo in (select cNo from course) and a.score between 85 and 100 and b.cNo in (select cNo from course) and b.score between 71 and 84 and c.cNo in (select cNo from course) and  c.score between 60 and 70 and d.cNo in (select cNo from course) and d.score<60
group by e.cNo,a.stuNo,b.stuNo,c.stuNo,d.stuNo
having a.stuNo<>b.stuNo and a.stuNo<>c.stuNo and a.stuNo<>d.stuNo and b.stuNo<>c.stuNo and b.stuNo<>d.stuNo and c.stuNo<>d.stuNo
select cNo,count(stuNo) from score
where score between 70 and 100 and cNo='c001'
group by cNo
--24.查询学生平均成绩及其名次
select stuNo,avg(score) from score
group by stuNo
order by avg(score) desc
--25.查询各科成绩前三名的记录:(不考虑成绩并列情况)
select a.stuNo,a.cNo,a.score
from score a
where a.score in (select top 3 score from score b
where a.cNo=b.cNo
order by score)
order by a.cNo
--26.查询每门课程被选修的学生数
select b.cNo ,count(stuNo) from score a right join course  b
on a.cNo=b.cNo
group by b.cNo
--27.查询出只选修了一门课程的全部学生的学号和姓名
select b.stuNo,a.stuName from student a,score b
where a.stuNo=b.stuNo
group by b.stuNo,a.stuName
having count(b.cNo)=1
--28.查询男生、女生人数
select stuSex,count(stuSex) from student
group by stuSex
--29.查询姓‘zhao’的学生名单
select * from student
where stuName like '赵%'  --30.查询同名同性学生名单,并统计同名人数
select a.stuNo,a.stuName,count(a.stuNo) from student a,student b
where a.stuName=b.stuName and a.stuSex=b.stuSex and a.stuNo<>b.stuNo
group by a.stuNo,a.stuName  --31.1981年出生的学生名单(注:Student表中Sage列的类型是datetime
--32.、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列
select cNo,avg(score) from score
group by cNo
order by avg(score) asc,cNo
--33.查询平均成绩大于70的所有学生的学号、姓名和平均成绩
select b.stuNo,a.stuName,avg(score) from student a,score b
where a.stuNo=b.stuNo
group by b.stuNo,a.stuName
having avg(score)>70
--34.查询课程名称为“java”,且分数低于70的学生姓名和分数
select a.stuName,b.score from student a,score b
where a.stuNo=b.stuNo and score<70 and b.cNo=(select cNo from course where cName='java')
--35.查询所有学生的选课情况
select a.stuNo,c.cNo from student a,score b,course c
where a.stuNo=b.stuNo and b.cNo=c.cNo
order by a.stuNo
select a.stuNo,cNo from student a left join (select a.stuNo,c.cNo from student a,score b,course c
where a.stuNo=b.stuNo and b.cNo=c.cNo) d
on a.stuNo=d.stuNo
order by a.stuNo
--36.查询任何一门课程成绩在70分以上的姓名、课程名称和分数
select a.stuName,b.cNo,score from student a,score b
where score>70 and a.stuNo=b.stuNo
--37.查询不及格的课程,并按课程号从大到小排列
select cNo,score from score
where score<60
order by cNo
--38.查询课程编号为003且课程成绩在60分以上的学生的学号和姓名
select b.stuNo,a.stuName from student a,score b
where b.cNo='c003' and score>60 and a.stuNo=b.stuNo
--39.求选了课程的学生人数
select count(a.stuNo) from (select distinct stuNo from score) a
--40.查询选修“赵”老师所授课程的学生中,成绩最高的学生姓名及其成绩
select b.stuNo,a.stuName,max(score) from student a,score b
where a.stuNo=b.stuNo and b.cNo in (select a.cNo from course a,teacher b where a.tNo=b.tNo and b.tName='钱市保')
group by b.stuNo,a.stuName,b.cNo
having b.cNo in (select a.cNo from course a,teacher b where a.tNo=b.tNo and b.tName='钱市保')
--41.查询各个课程及相应的选修人数
select cNo,count(stuNo) from score
group by cNo
select b.cNo ,count(stuNo) from score a right join course  b
on a.cNo=b.cNo
group by b.cNo
--42.查询不同课程成绩相同的学生的学号、课程号、学生成绩
select a.stuNo,a.cNo,a.score from score a,score b
where a.stuNo=b.stuNo and a.score=b.score and a.cNo<>b.cNo
--43. 查询每门功成绩最好的前两名
select a.stuNo,a.cNo,a.score
from score a
where score in(select top 2 score from score b
where a.cNo=b.cNo
order by score desc)
order by a.cNo
--44.统计每门课程的学生选修人数(超过2人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列
select cNo,count(stuNo) 课程数 from score
group by cNo
having count(stuNo)>2
order by count(stuNo) desc,cNo
--45.检索至少选修两门课程的学生学号
select stuNo from score
group by stuNo
having count(cNo)>=2
--46.查询全部学生都选修的课程的课程号和课程名
select a.cNo,b.cName from score a,course b
where a.cNo=b.cNo
group by a.cNo,b.cName
having count(a.stuNo)=(select count(stuNo) from student)
select a.cNo,b.cName from score a,course b
group by a.cNo,b.cName,b.cNo
having a.cNo=b.cNo and count(a.stuNo)=(select count(stuNo) from student)
--47.查询没学过“钱”老师讲授的任一门课程的学生姓名
select stuNo,stuName from student
where stuNo not in (select stuNo from score a,course b,teacher c
where a.cNo=b.cNo and b.tNo=c.tNo and c.tName='钱市保'
group by stuNo
having count(a.cNo)<=(select count(cNo) from course d,teacher e
where d.tNo=e.tNo and e.tName='钱市保'))
select stuNo,stuName from student
where stuNo not in
(select stuNo from score where cNo in
(select cNo from teacher c,course d where c.tNo=d.tNo and c.tName='钱市保'))
--48.查询两门以上不及格课程的同学的学号及其平均成绩
select stuNo,avg(score) from score
where score<60
group by stuNo
having count(cNo)>2
--49.检索“004”课程分数小于60,按分数降序排列的同学学号
select stuNo from score
where score<60 and cNo='c004'
order by score desc
--50.删除“2”同学的“001”课程的成绩
delete from score where stuNo='002' and cNo='c001'  

50条经典(学生,课程,成绩,教师)表SQL语句~~值得一看!相关推荐

  1. 学生-课程-成绩-教师表的设计

    学生-课程-成绩-教师表的设计 这个是最简单,也是最常用,但也是最基本的,很多设计都可以从它的身上推到出来滴呀: ps:本文,重在体现设计思路 和 表之间的关系,不要过于纠结字段命名是否规范,或者是否 ...

  2. 基于区块链的学生课程成绩查询系统

    基于区块链的学生课程成绩查询系统 [摘 要]传统成绩管理系统存在数据易窜改的问题.本文根据区块链不可窜改的原理设 计并实现课程成绩查询系统.系统基于以太坊技术开发,采用 Node.js 作为服务器后端 ...

  3. mysql查询建表SQL语句

    前言 mysql 5.7.26 查询建表SQL语句 SHOW CREATE TABLE <表名> 示例1: shell> mysql -uroot -p Enter password ...

  4. powerdesigner生成表sql语句时,统一添加默认字段(生成时间、生成人等)

    powerdesigner生成表sql语句时,统一添加默认字段 文章目录 powerdesigner生成表sql语句时,统一添加默认字段 方式一:配置创建表默认字段: 方法二:创建表模型后执行vb语句 ...

  5. 数据库——python操作MySQL、修改表SQL语句、视图、触发器、存储过程、事务、流程控制、常见函数、索引

    文章目录 一.python操作MySQL 1.pymysql模块 1.基本使用 2.sql注入问题 3.二次确认 二.修改表SQL语句 1.修改表的名字 rename 2.添加字段 add 3.修改字 ...

  6. 数据库地区表sql语句,数据库地区表包含省市县

    数据库地区表sql语句,数据库地区表包含省市县 包含省市县的数据表,需要的可以参考,sql语句一个博客字数太多发布不了,剩下的在下一个博客里面,之前也是在网上找的,感谢分享 -- ---------- ...

  7. oracle创建主键sql语句,Oracle创建主键自增表(sql语句实现)及触发器应用

    Oracle创建主键自增表(sql语句实现)及触发器应用 1.创建表 复制代码 代码如下: createtableTest_Increase( useridnumber(10)NOTNULLprima ...

  8. mysql语句生成在线_在线数据库表(sql语句)生成java实体类工具

    相信每个做java开发的读者,都接触过SQL建表语句,尤其是在项目开发初期,因为数据库是项目的基石. 在现代项目开发中,出现了许多ORM框架,通过简单的实体映射,即可实现与数据库的交互,然而我们最初设 ...

  9. 【数据库设计】学生学籍信息和学期学年课程成绩信息表以及插入数据的python脚本生成设计

    [数据库设计]学生学籍信息和学年学期课程成绩信息设计 参考登陆用户信息设计 学籍信息设计 课程成绩信息设计 其他表的补充 专业-学院对照表 班级信息表 课程表 插入数据脚本 错误提示 参考登陆用户信息 ...

最新文章

  1. C# checked、unchecked操作符
  2. ELK/EFK — Overview
  3. HDU 5624 KK's Reconstruction
  4. 德国汽车厂发生机器人杀人事件 人机协作是大势所趋
  5. 如何玩转CSS列表样式?速查!
  6. WINCE Driver 心得总结
  7. 写入缓存 还是 直接 写入 json 方便,
  8. Homebrew命令具体解释
  9. js两个等号和三个等号_这两个号段开头的手机号,已成“古董号”,手里有的保存好...
  10. 7-1 计算物体自由下落的距离 (5 分)
  11. 计算机中答案没有小数怎么办,嵌入式编程中计算机是如何存储小数的
  12. 2019年360笔试
  13. 在 linux ubuntu 18.04 上运行QQ音乐
  14. layui table动态选中_NeurIPS 2020 | 伯克利新工作: 基于动态关系推理的多智能体轨迹预测问题...
  15. python ccf题解 201409-1 相邻数对
  16. c语言用指针升序降序,C语言函数序——升序降序.doc
  17. Andriod编程基础(一):Andriod的优势及光明前景
  18. 微信支付『支付失败,如果已扣款,资金在0-3个工作日原路返回』踩坑案例及解决方案
  19. 《功夫》“经典”台词
  20. More than 1 blank line not allowed

热门文章

  1. sql server使用教程(图文)
  2. 苹果 macOS 12.4 正式版发布
  3. 自动驾驶决策规划算法第一章笔记 忠厚老实的老王
  4. 【CSDN 2022 年度征文】你不停的翻找答案,只不过是在找一个替你讲故事的人——Oracle DBA转型大数据开发DBA的自述
  5. 《数据仓库与数据挖掘教程》ch01绪论 章节整理
  6. 双目相机实现物体三维重建,得到三维点云
  7. 【OpenCV 例程300篇】214. 绘制椭圆的参数详解
  8. Scrapy爬虫框架视频学习
  9. jq.1.10.2.min.js中报错最后一行得解决办法
  10. gensim : AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0.