course:

teachar:

student

sc:

1、查询“c001”课程比“c002”课程成绩高的所有学生的学号;

select a.sid from

(select sid,score from sc where cid=001) as a,

(select sid,score from sc where cid=002) as b

where a.score > b.score and a.sid=b.sid;

2、查询平均成绩大于60 分的同学的学号和平均成绩;

select sid,score from sc

group by sid having avg(score);

3、查询所有同学的学号、姓名、选课数、总成绩;

select student.sid,student.sname,count(SC.cid),sum(score)

from student inner join sc on student.sid=sc.sid

group by student.sid,sname;

4、查询姓“刘”的老师的个数;

select count(tName) from teacher

where tName like '刘%';

5、查询没学过“李老师”课的同学的学号、姓名;

select sid,sname from student where

sid not in (select distinct(sc.sid) from teacher,course,sc

where teacher.tName='李老师' and teacher.tid=course.tid and course.cid=sc.cid);

6、查询学过“c001”并且也学过编号“c002”课程的同学的学号、姓名;

select student.sid,student.sname from student,sc

where student.sid=sc.sid and sc.cid=001 and exists(select * from sc as sc2

where sc2.sid=sc.sid and sc2.cid=002);

7、查询学过“李老师”所教的所有课的同学的学号、姓名;

select sid,sname from student

where sid in (select sid from teacher,course,sc

where teacher.tName='李老师' and teacher.tid=course.tid and course.cid=sc.cid

group by sid having count(sc.cid)=(select count(cid) from teacher,course

where teacher.tid=course.tid and teacher.tName='李老师'));

8、查询课程编号“c002”的成绩比课程编号“c001”课程低的所有同学的学号、姓名;

select student.sid,student.sname from student,

(select sid,score from sc where cid=001) as a,

(select sid,score from sc where cid=002) as b

where a.score>b.score and student.sid=a.sid and student.sid=b.sid;

9、查询所有课程成绩小于60 分的同学的学号、姓名;

select sid,sname from student

where sid not in (select student.sid from student,sc

where student.sid=sc.sid and sc.score>60);

10、查询没有学全所有课的同学的学号、姓名;

select student.sid,student.sname from sc,student

where sc.sid=student.sid

group by sid having count(sc.cid)!=(select count(cid) from course);

11、查询至少有一门课与学号为"1001"的同学所学相同的同学的学号和姓名;

select student.sid,student.sname from student,sc

where student.sid=sc.sid

and sc.cid in (select cid from sc where sid=1001)

group by sid;

12、统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60]

select course.cid,course.cname,count(sc.cid),

sum(case when sc.score>=85 and sc.score<=100 then 1 else 0 end) '100-85',

sum(case when sc.score>=70 and sc.score<=85 then 1 else 0 end) '85-70',

sum(case when sc.score>=60 and sc.score<=70 then 1 else 0 end) '70-60',

sum(case when sc.score<=60 then 1 else 0 end) '60-0'

from course,sc

where course.cid=sc.cid

group by cid

13、查询出只选修了一门课程的全部学生的学号和姓名

select sc.sid,student.sname from student,sc

where student.sid=sc.sid

group by sc.sid having count(sc.cid)=1

14、查询男生、女生学生人数

select ssex,count(ssex) from student

group by ssex

15、查询姓"张"的学生名单

select sname from student

where sname like '张%'

16、查询同名同性学生名单,并统计同名人数 、

select sname,count(sname) from student

GROUP BY sname,ssex

having count(sname)>1

17、查询1981年出生的学生名单(注:student表中sage列的类型是datetime)

select sname,sage from student

where year(sage)=1981

18、查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列

select cid,avg(score) from sc

GROUP BY cid

ORDER BY avg(score),cid desc

19、查询课程名称为"数据库",且分数低于60的学生姓名和分数

select student.sname,sc.score from student,course,sc

where course.cname='数据库' and course.cid=sc.cid and sc.score<60 and student.sid=sc.sid

20、查询任何一门课程成绩在70分以上的姓名、课程名称和分数;

select student.sname,course.cname,sc.score from student,sc,course

where course.cid=sc.cid and student.sid=sc.sid and sc.score>70

查询课程数mysql_mysql_数据查询练习相关推荐

  1. SELECT高级查询——连接查询、子查询(多表数据查询)

    在实际中,经常是从多张表中查询数据.本节学习多表连接查询.子查询等高级SELECT语句的应用. 1.简单连接查询 多表查询是指SELECT命令中显示的列来源于多个数据表: 连接查询将多个表以某个或某些 ...

  2. SQL查询效率:100w数据查询只需要1秒钟

    机器情况 p4: 2.4 内存: 1 G os: windows 2003 数据库: ms sql server 2000 目的: 查询性能测试,比较两种查询的性能 SQL查询效率 step by s ...

  3. Web前端工作笔记002---json数据查询的方法_json查询大全,JsonSQL数据查询,jfunk数据查询

    JAVA技术交流QQ群:170933152 json数据查询的方法 网上看到有一篇帖子,有8种json数据查询的方法,大家可以研究一下,我现在分享一下! JsonSQL JsonSQL实现了使用SQL ...

  4. 十八、AR数据库的关联查询relations之单条数据查询

    为什么80%的码农都做不了架构师?>>>    我们已经了解了怎样通过AR从单个数据表中获取数据,那么如果要关联多个数据表,AR又应该怎样操作列 我们看到,在 创建的AR模型User ...

  5. mysql查询1万条数据要1秒钟_SQL查询效率:100w数据查询只需要1秒钟

    机器情况 p4: 2.4 内存: 1 G os: windows 2003 数据库: ms sql server 2000 目的: 查询性能测试,比较两种查询的性能 SQL查询效率 step by s ...

  6. 姓张信息mysql_MySQL_数据查询

    select from [where] [group] [having] [order by] [limit] [union] 1.查看数据的两种方法 select 字段名 from 表名; 查看多指 ...

  7. db2怎么限定查询条数_如何查询各国进口关税税率!

    那么问题来了, 如何查询各国进口关税税率 ? 这里主要介绍一些综合性的网站! 1.商务部公共商务信息服务 http://wmsw.mofcom.gov.cn/wmsw/ 这个网站由中国国际电子商务中心 ...

  8. mysql查询周数_MySQL:查询中从周数开始的周日期范围

    我有一个数据库表,看起来像这样: | id | clock | info ---------------------------------------------- | 1 | 1262556754 ...

  9. ajax 制作表格带查询参数,查询表格——建立动态表格,使用ajax输入查询条件将后台数据查询出来以表格的形式展示出来...

    function search(){ $.ajax({ type:'Post', url:"FtpAction_listUserQuery", data:{ telephone:$ ...

最新文章

  1. [微信官方文档] 小程序-错误码信息与解决方案表
  2. PointNet++论文个人理解
  3. C语言清空输入缓冲区的N种方法对比(转)
  4. POJ 1661 Help Jimmy(递推DP)
  5. date制作电子时钟
  6. Apache默认端口80被占用无法启动服务问题
  7. 差分电荷密度怎么画_科学网差分电荷密度图、电荷局域密度图(ELF)的画
  8. api 定位 微信小程序 精度_微信小程序城市定位(百度地图API)
  9. matlab计算macd_matlab计算MACD指标
  10. 如何使用键盘快捷键在Mac上录制屏幕?
  11. android扫雷PPT,《扫雷游戏制作》PPT课件.ppt
  12. python bin文件转换成txt文件
  13. 使用Apache FtpServer搭建FTP服务器 [FlashFXP]
  14. vtp服务器作用,VTP
  15. Mezzanine user 扩展
  16. Mysql数据库简要介绍
  17. 什么是机器视觉? 和计算机视觉有什么区别?
  18. 2021开源免费CMS建站系统怎么选择?
  19. 手机预览ps设计稿在哪里
  20. 使用Bmob遇到的坑与解决办法

热门文章

  1. 电脑硬件知识入门之显卡篇
  2. oracle 倒库详细步骤,新手倒车入库怎么操作 图文并茂详细讲解操作技巧
  3. oCPC基础知识了解
  4. PreScan快速入门到精通第三十二讲基于PreScan进行毫米波雷达传感器仿真
  5. php ppt如何转换成pdf,ppt转pdf格式转换器 PPT批量转换成PDF 怎样把PPT格式转换成PDF格式...
  6. MobileNetV2:Inverted Residuals and Linear BottleNecks
  7. python 百分号调用内置函数_建议你吃透python这68个内置函数!
  8. 调用高德地图API接口,实现地铁站经纬度采集
  9. 图像处理 灰度变换与空间滤波
  10. NetSuite 使用库存盘点