学习目标:
sql
学习内容:
做一些练习题,从简单到难
50题目参照的这个博客http://t.csdnimg.cn/caZfX,有改动,根据表的实际数据来的
下面是建立的四张表
第一张课程表

第二张教师表

第三张学生表

第四张成绩表(这里做了分页)

1.查询「李」姓老师的数量
分析题目:使用count()和模糊查询
select count() from teacher where name like ‘哈%’;

2.查询男生、女生人数
分析题目:使用count()和group by 分组
select gender ‘性别’ , count() ‘数量’ from students group by gender;

3.查询名字中含有「2」字的学生信息
分析题目:使用模糊查询
selectfrom students where name like ‘%2%’;

4.查询同名同性学生名单,并统计同名人数
分析题目:使用count()和group by 分组
select name,gender,count() from students group by name,gender order by gender;

呀,没有同名的,插入一组数据

重新查询,okk

看了一下参考答案,有having,修正一下
select name,gender,count() from students group by name,gender having count()>1 ;

5.查询 2001 年出生的学生名单
分析题目:模糊查询
select*from students where birthday like ‘%2001%’;

参考答案
select *from student where year(birthday) = 1990;
6.查询平均成绩大于等于 60 的所有学生的学号、姓名和平均成绩
分析题目:group by 、avg()
select students.stunm,students.name,avg(score.tscore) from students,score group by students.stunm,students.name having avg(score.tscore)>=60;

参考答案
select students.stunm, students.name, AVG(score.tscore) as aver from students, score where students.stunm=score.stunm group by students.stunm having aver >=60;
学习时间:
1月-3月,每天一小时左右
学习产出:
一周一发
本文介绍了在SQL学习过程中,通过一系列基础查询练习,如统计李姓老师数量、男女学生人数、特定条件下筛选学生等,以及如何使用GROUPBY和HAVING进行复杂数据分析。学习者在1月至3月间,每天投入大约一小时,每周发布一次学习成果,关注于成绩表的关联查询和平均成绩计算。

被折叠的 条评论
为什么被折叠?



