- 1、本文档共16页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
经典SQL面试题
删除除了学号字段以外,其它字段都相同的冗余记录!
要求结果数据:
原始数据:
CREATE TABLE tbl_students (
id number(32) NOT NULL,
name varchar(10) DEFAULT NULL,
sax varchar(10) DEFAULT NULL,
age number(6) DEFAULT NULL,
PRIMARY KEY (id)
)
insert into tbl_students (id, name, sax, age) values(2,李四,男,21);
insert into tbl_students (id, name, sax, age) values(3,张三,女,17);
insert into tbl_students (id, name, sax, age) values(4,李四,男,12);
insert into tbl_students (id, name, sax, age) values(6,凤姐,女,20);
insert into tbl_students (id, name, sax, age) values(5,凤姐,女,20);
insert into tbl_students (id, name, sax, age) values(7,田七,男,18);
insert into tbl_students (id, name, sax, age) values(1,田七,男,18);
insert into tbl_students (id, name, sax, age) values(8,张三,男,17);
答案:
mySql
DELETE FROM student WHERE sid NOT IN (SELECT sid FROM ((SELECT MIN(sid) sid FROM student GROUP BY sName,sSex ))t)
oracle:
DELETE FROM student WHERE sid NOT IN(SELECT MIN(sid) sid FROM student GROUP BY sName,sSex )
查询各科成绩都及格的学员
(要求查询出参加考试的各科成绩都高于60分,不管参加了多少科考试)
要求结果:
表:
CREATE TABLE tbl_score (
id NUMBER(10) NOT NULL,
username varchar(20) DEFAULT NULL,
course varchar(20) DEFAULT NULL,
score NUMBER(10) DEFAULT NULL,
PRIMARY KEY (id)
)
数据:
insert into tbl_score (id, username, course, score) values(1,张三,语文,50);
insert into tbl_score (id, username, course, score) values(2,张三,数学,80);
insert into tbl_score (id, username, course, score) values(3,张三,英语,90);
insert into tbl_score (id, username, course, score) values(4,李四,语文,70);
insert into tbl_score (id, username, course, score) values(5,李四,数学,80);
insert into tbl_score (id, username, course, score) values(6,李四,英语,80);
insert into tbl_score (id, username, course, score) values(7,王五,语文,50);
insert into tbl_score (id, username, course, score) values(8,王五,英语,70);
insert into tbl_score (id, username, course, score) values(9,赵六,数学,90);
答案:
select username,scor from tbl where id not in (select id from tbl where score 60)
表(MYSQL)
Student(sid,Sname,Sage,Ssex) 学生表
Course(cid,Cname,tid) 课程表
CREA
文档评论(0)