可以看到,最下方的第3题可能不太全,但是影响不大,看不见的那就先不管。
一.第一题
1.建表语句
create table test1( id varchar(20), name varchar(20)) charset=utf8;insert into test1(id,name) values("1001","张三"),("1002","李四"),("1003","王五"),("1003","王五"),("1004","陈六");
结果如下:
2.请用一条SQL语句,查询去重后的人员信息清单
select id,namefrom test1group by id,name;--------------------------------或者---------select distinct(id),namefrom test1
结果如下:
3.请用一条SQL语句,查询出存在重复记录的人员id
select id,count(id) countsfrom test1group by idhaving counts >=2;
结果如下:
二.第二题
1.建表语句
# math_table表create table math_table( id int, name varchar(20), math_score int) charset=utf8;insert into math_table(id,name,math_score) values(1,"李明",83),(3,"张建国",76),(5,"王华",57);=============================================# english_table表create table english_table( id int, name varchar(20), english_score int) charset=utf8;insert into english_table(id,name,english_score) values(2,"陈斌",73),(3,"张建国",65),(5,"王华",89);
结果如下:
2.请用一条SQL语句,查询出两项比赛都参加了的学生的name清单
select a.id,a.name,a.math_score,b.english_scorefrom math_table ajoin english_table bon a.id = b.id
结果如下:
3.请用一条SQL语句,查询出参加了数学竞赛但是没有参加英语竞赛的学生的name清单
select a.id,a.name,a.math_score from math_table aleft join english_table bon a.id = b.id where b.english_score is null;
结果如下:
4.请用一条SQL语句,查询出两项竞赛得分均大于60分的学生的两项竞赛的平均分
selecta.id,a.name,(a.math_score+b.english_score)/2 as avgfrommath_table ajoinenglish_table bona.id = b.idwherea.math_score >=60 and b.english_score >=60;
结果如下:
END.
作者:黄伟呢
来源:数据分析与统计学之美
本文已和作者授权,如需转载请与作者联系
- 我的微信公众号
- 微信扫一扫
-
- 我的微信公众号
- 微信扫一扫
-
评论