Sql 常见面试题(总结) 1. 用一条 SQL 语句查询出每门课都大于 80 分的学生姓名 name kecheng fenshu 张三语文 81 张三数学 75 李四语文 76 李四数学 90 王五语文 81 王五数学 100 王五英语 90 (1) select stu_name from stu_grade minus select stu_name from stu_grade g where <= 80 (2) select distinct stu_name from stu_grade ou where not exists ( select 1 from stu_grade inn where = and <= 80 )(3) select distinct from stu_grade t1 where not in ( select distinct from stu_grade t2 where <= 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学号, 姓名, 课程编号, 课程名称, 分数) ★:(1 )在 where 的左右都不能使用“组函数”; (2 )一般来说,都可以使用 exists 代替 in, 如果在 in 的条件中使用了“组函数”查询到值,那么就不能使用 exists 来代替 in 了,就像本题一个叫 department 的表,里面只有一个字段 name, 一共有 4 条纪录,分别是 a,b,c,d, 对应四个球对,现在四个球对进行比赛,用一条 sql 语句显示所有可能的比赛组合. 你先按你自己的想法做一下,看结果有我的这个简单吗? 答: select , from team a, team b where < 请用 SQL 语句实现:从 TestDB 数据表中查询出所有月份的发生额都比 101 科目相应月份的发生额高的科目。请注意: TestDB 中有很多科目,都有 1- 12 月份的发生额。 AccID :科目代码, Occmonth :发生额月份, ur :发生额。数据库名: JcyAudit ,数据集: Select * from TestDB 答: select a.* from TestDB a ,(select Occmonth,max(ur) ur from TestDB where AccID='101' group by Occmonth) b where = and > ******************************************************************************* ***** 面试题:怎么把这样一个表儿 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 这个是 ORACLE 中做的: select * from (select name, year b1
sql面试题 来自淘豆网m.daumloan.com转载请标明出处.