sql语句测试题
更新时间:2023-11-14 07:42:01 阅读量: 教育文库 文档下载
Students学生表(SId:学号;Sname:学生姓名;age:学生年龄;sex:学生性别) Courses课程表(CId,课程编号;Cname:课程名字;TId:教师编号) SC成绩表(SId:学号;CId,课程编号;grade:成绩) Teachers教师表(TId:教师编号; Tname:教师名字) 问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学生学号; select sno from sc a where
(select grade from sc b where b.cno=001 and b.sno=a.sno) < (select grade from sc c where c.cno=002 and c.sno=a.sno)
select * from sc a, sc b where
a.sno=b.sno and a.cno=001 and b.cno=002 and a.grade 2、查询平均成绩大于60分的同学的学号和平均成绩; Select sno, avg(grade) from sc group by sno having avg(grade) > 60; 3、查询所有同学的学号、姓名、选课数、总成绩; Select a.sno,a.sname, count(*), sum(b.grade) from students a, sc b where a.sno=b.sno group by sno; 4、查询姓“李”的老师的个数; Select count(*) from teachers where tname like ‘李%’; 5、查询没学过“叶平”老师课的同学的学号、姓名; Select sno, sname from students where sno not in (Select sno from sc where cno in (Select cno from courses where tno=(Select tno from tearchers where tname=’叶平’))) select * from students where sno not in (select sno from sc a, courses b where a.cno=b.cno and b.tno=(select tno from teachers where tname='叶平')); select * from students s where not exists (select * from sc a, courses b where a.cno=b.cno and b.tno=(select tno from teachers where tname='叶平') and s.sno=a.sno); 6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名; select * from students where sno in (select a.sno from sc a, sc b where a.sno=b.sno and a.cno=001 and b.cno=002); select * from students where sno in (select a.sno from (select * from sc where cno=001) a, (select * from sc where cno=002) b where a.sno=b.sno); select a.sno,a.sname from students a, sc b where a.sno=b.sno and b.cno in (001,002) group by a.sno,a.sname having count(*)=2; 7、查询所有课程成绩小于60分的同学的学号、姓名; select sno from sc group by sno having max(grade)<60; select a.sno, a.sname from students a where 60 > all (select grade from sc b where a.sno=b.sno) 8、查询没有学全所有课的同学的学号、姓名; select sno from sc group by sno having count(*) < (select count(*) from courses) 9、删除学习“叶平”老师课的SC表记录; Delete [from] sc where cno in (Select cno from courses where tno=(Select tno from tearchers where tname=’叶平’))) 10、查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分 Select cno, max(grade), min(grade) from sc group by cno 11、查询每门课程被选修的学生数 Select cno, count(*) from sc group by cno 12、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列 Select cno, avg(grade) from sc group by cno order by avg(grade) asc, cno desc 13、查询课程编号为003且课程成绩在80分以上的学生的学号和姓名; Select sno, sname from students where sno in(Select sno from sc where cno=’003’ and grade > 80) 14、检索“004”课程分数小于60的同学学号,按分数降序排列 Select sno from sc where cno=’004’ and grade<60 order by grade desc 15、删除“002”同学的“001”课程的成绩 Delete [from] sc where sno=’002’ and cno=’001’
正在阅读:
sql语句测试题11-14
关联翻译理论研究的回顾与展望读书笔记06-21
现代文考点一、理解文中重要词语的含义08-12
优秀校长资料01-11
列车长怎样有效提高班组的应急处理能力06-20
人教版六年级数学下学期第6单元3统计与概率教案第1课时 统 计02-26
数据结构课设--迷宫08-07
新人教版小学数学四年级下册第三单元《运算定律与简便运算》单元测试卷09-18
英语语法填空常见的词语变形(1)05-01
中日军事力量的真实对比10-19
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 测试题
- 语句
- sql
- 备考2019届高考语文三年真题(2016-2018)分项版解析:专题05 古典诗歌鉴赏(原卷版)
- 我国混合动力汽车发展现状研究毕业论文
- linux实验及课程设计
- 最新人教版高中地理必修一全册教案汇编
- 最新苏教版六年级语文上册第四单元测试题及答案
- 对外汉语选题题库
- 2017年德州市法律援助案件卷宗整理细则(1)要点
- 生产运作管理计算题及答案 - 图文
- 民族文化艺术节主持词
- 小学三年级下册研究性学习教案
- OSPF,ISIS,BGP常见问题
- 煤矿石门揭煤程序及步骤
- FTTH认证试题库
- 创建廉洁文化示范单位实施方案
- 会籍顾问
- 2017-2022年中国银饰品市场需求现状调研及十三五投资趋势研究报告(目录)
- 7 HXD1D机车途中故障应急处理解密1 - 图文
- 《数学分析选讲》第一次(主观题)作业答案
- 机构创新实例--2009
- 《西方文化概论》选修课实用考试答案