1 / 5
文档名称:

SQL经典面试题及答案.docx

格式:docx   大小:19KB   页数:5页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

SQL经典面试题及答案.docx

上传人:mh900965 2018/2/14 文件大小:19 KB

下载得到文件列表

SQL经典面试题及答案.docx

文档介绍

文档介绍:SQL经典面试题及答案
1. 用一条SQL 语句查询出每门课都大于80 分的学生姓名
name kecheng fenshu 
张三语文 81
张三数学 75
李四语文 76
李四数学 90
王五语文 81
王五数学 100
王五英语 90
A: select distinct name from table where name not in (select distinct name from table where fenshu<=80)
   select name from table group by name having min(fenshu)>80
  select name from table group by name having count(kecheng)>=3 and min(fenshu)>=80
 
 
2. 学生表如下:
自动编号学号姓名课程编号课程名称分数
1 2005001 张三 0001 数学 69
2 2005002 李四 0001 数学 89
3 2005001 张三 0001 数学 69
删除除了自动编号不同, 其他都相同的学生冗余信息
A: delete tablename where 自动编号 not in(select min( 自动编号) from tablename group by 学号, 姓名, 课程编号, 课程名称, 分数)
 
3. 面试题:怎么把这样一个表儿
year month amount
1991 1
1991 2
1991 3
1991 4
1992 1
1992 2
1992 3
1992 4
查成这样一个结果
year m1 m2 m3 m4
1991
1992
答案一、
select year, 
(select amount from aaa m where month=1 and =) as m1,
(select amount from aaa m where month=2 and =) as m2,
(select amount from aaa m where month=3 and =) as m3,
(select amount from aaa m where month=4 and =) as m4
from aaa group by year
 
4. 说明:拷贝表( 拷贝数据, 源表名:a 目标表名:b)
SQL: insert into b(a, b, c) select d,e,f from a;
 
,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路): 
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。 
显示格式: 
语文数学英语 
及格优秀不及格