sql面试题及答案
name kecheng fenshu
张三 数学 75
李四 数学 90
王五 数学 100
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 count(kecheng)>=3 and min(fenshu)>=80
自动编号 学号 姓名 课程编号 课程名称 分数
2 2005002 李四 0001 数学 89
删除除了自动编号不同, 其他都相同的学生冗余信息
3. 面试题:怎么把这样一个表儿
1991 1 1.1
1991 3 1.3
1992 1 2.1
1992 3 2.3
查成这样一个结果
1991 1.1 1.2 1.3 1.4
答案一、
(select amount from aaa m where month=1 and m.year=aaa.year) as m1,
(select amount from aaa m where month=3 and m.year=aaa.year) as m3,
from aaa group by year
SQL: insert into b(a, b, c) select d,e,f from a;
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。
语文 数学 英语
------------------------------------------
(case when 语文>=80 then '优秀'
else '不及格') as 语文,
when 数学>=60 then '及格'
(case when 英语>=80 then '优秀'
else '不及格') as 英语,
6、编写SQL语句
Create table stu (学号 int ,
年龄 int,
家庭地址 varchar(50),
);
Alter table stu add 学历 varchar(6);
Alter table stu drop column 家庭地址
学号 姓名年龄性别联系电话学历
2B21男119中学
4D18女114大学
Insert into stu values(2,’B’,21,’男’,119,’中学’)
Insert into stu values(4,’D’,18,’女’,114,’大学’)
Update stu set 学历=’大专’ where 联系电话 like ‘11%’
Delect from stu where 性别=’男’ and 姓名 like ‘c%’
Select 姓名,学号 from stu where 年龄<22 and 学历=’大专’
Select top 25 percent * from stu
Select 姓名,性别 from stu order by 年龄 desc
Select avg(年龄) from stu group by 性别
select top 10 * from A where ID >(select max(ID) from (select top 30 ID from A order by A ) T) order by A
select * from(select count(ID) as count from table group by ID)T where T.count>3
AVG:求平均值
MAX:求最大值
COUNT(*):返回所有行数
事务 Transaction 触发器 TRIGGER 继续 continue 唯一 unqiue
约束 constraint
10、说明:随机取出10条数据
11、查询平均成绩大于60分的同学的学号和平均成绩;
select stuId,avg(score)
from Scores
group by stuId having avg(score) >60;
原文链接:http://www.jxszl.com/biancheng/shujuku/445397.html