这是别人发的一道MySQL面试题
,别人要求你在15分钟内完成。一眼看过去,这张面试题并非很难,可是你能不能很快作出来呢?能够看到,最下方的第3题可能不太全,可是影响不大,后面的那就先无论。
web
create table test1( id varchar(20), name varchar(20) ) charset=utf8; insert into test1(id,name) values ("1001","张三"), ("1002","李四"), ("1003","王五"), ("1003","王五"), ("1004","陈六");
结果以下:
面试
select id,name from test1 group by id,name; ---------------------- ----------或者--------- select distinct(id),name from test1
结果以下:
sql
select id,count(id) counts from test1 group by id having counts >=2;
结果以下:
svg
# 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);
结果若是:
spa
select a.id,a.name,a.math_score,b.english_score from math_table a join english_table b on a.id = b.id
结果以下:
3d
select a.id,a.name,a.math_score from math_table a left join english_table b on a.id = b.id where b.english_score is null;
结果以下:
code
select a.id,a.name,a.math_score,b.english_score from math_table a join english_table b on a.id = b.id where a.math_score >=60 and b.english_score >=60;
结果以下:
xml