SQL面试题

来源:互联网 发布:hitleap类似的软件 编辑:程序博客网 时间:2024/05/19 04:25


查询出三门成绩都大于80 的学生



解析:

第一种 sql嵌套

select "name" from "Chenji" where "subject"='英语' and "score" >=80 and "name" in

(  select "name" from "Chenji" where "subject"='数学' and "score" >=80 and "name" in 
(SELECT "name" FROM "Chenji" where "subject"='语文' and "score" >=80))


第二种intersect 取交集
select "name" from "Chenji" where "subject"='英语' and "score" >=80
intersect 
select "name" from "Chenji"  where "subject"='数学' and "score" >=80
intersect
select "name" from "Chenji"  where "subject"='语文' and "score" >=80

第三种取差集
select distinct "name" from "Chenji"
where "name" not in
(select "name" from "Chenji" where "score"<80)
0 0
原创粉丝点击