题目一、
有两个表:
TableX有三个字段Code、 Name、 Age、 其中Code为主键;
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下:
Code Name Age Code Class Score
97001 张三 22 97001 数学 80
97002 赵四 21 97002 计算机 59
97003 张飞 20 97003 计算机 60
97004 李五 22 97004 数学 55
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
2、请写出SQL,取出计算机科考成绩不及格的学生;
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
题目二、
有两个表定义如下:
create tableindividual (
firstname varchar2(20) not null
lastname vatchar2(20) not null
birthdate date
gender varchar2(1)
initial number(2)
farorite varchar2(6)
type varchar2(8)
);在此表中建唯一索引 firstname + lastnamecreate table chile_detail(
firstname varchar2(20)
lastname varchar2(20)
cname varchar2(8)
coment varchar2(2)
type varchar2(8)
);
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”
有两个表:
TableX有三个字段Code、 Name、 Age、 其中Code为主键;
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下:
Code Name Age Code Class Score
97001 张三 22 97001 数学 80
97002 赵四 21 97002 计算机 59
97003 张飞 20 97003 计算机 60
97004 李五 22 97004 数学 55
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
2、请写出SQL,取出计算机科考成绩不及格的学生;
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
题目二、
有两个表定义如下:
create tableindividual (
firstname varchar2(20) not null
lastname vatchar2(20) not null
birthdate date
gender varchar2(1)
initial number(2)
farorite varchar2(6)
type varchar2(8)
);在此表中建唯一索引 firstname + lastnamecreate table chile_detail(
firstname varchar2(20)
lastname varchar2(20)
cname varchar2(8)
coment varchar2(2)
type varchar2(8)
);
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”
解决方案 »
- 会员系统的基础表结构设计问题,实现快速索引
- 为什么我的trigger这样写不起作用啊
- 这SQL文是干什么用的?其结果说明了什么?
- HELP!HELP!HELP!关于数据导入、导出的问题
- 关于mysql的创建视图的语句转换成oracle里面创建视图的语句
- 什么是Sort Merge Join(SMJ)连接?
- 求一条关于树的sql语句
- Oracle 支持的SQL中 用什么函数据把字符串转换成整型???
- 有没有办法在linux下自动启动oracle的监听服务???
- 关于SQL语句中如何判断where后某结果集是否为空的问题
- oracle去除重复行并且对结果字段求和
- Oracle.DataAccess.Client.OracleException ORA-06550: 第 1 行, 第 7 列: PLS-00103: 出现符号 "{"在需要下列之一时: 错误是什么原因?
delete from x
where code not in(select code from y)
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下: Code Name Age Code Class Score
97001 张三 22 97001 数学 80
97002 赵四 21 97002 计算机 59
97003 张飞 20 97003 计算机 60
97004 李五 22 97004 数学 55
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
select * from TableX where name like '张%' order by age2、请写出SQL,取出计算机科考成绩不及格的学生;
select * from tableX where code in (select code from tableY WEHRE class='计算机' and score<60)3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
select a.name,b.class,b.score from tableX a,tableY b where a.code=b.code 4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
select a.name,b.class,b.score from tableX full join tableY on a.code=b.code5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
insert into tablex values('97005','赵六',20)
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
update tablex set age=21 where code='97004'7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
delete tablex where code not in (select code from tabley)
DELETE TABLEX WHERE CODE IN (
SELECT CODE FROM TABLEX WHERE CODE NOT IN(SELECT Y.CODE FROM TABLEY))
但看了其它人的写法,感觉自己写的不简洁,学习一下.
有两个表: TableX有三个字段Code、 Name、 Age、 其中Code为主键;
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下: Code Name Age Code Class Score
97001 张三 22 97001 数学 80
97002 赵四 21 97002 计算机 59
97003 张飞 20 97003 计算机 60
97004 李五 22 97004 数学 55
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
select code,name,age from tableX where name like '张%' ORDER BY AGE
2、请写出SQL,取出计算机科考成绩不及格的学生;
SELECT Y.NAME,X.CLASS,X.SCORE FROM TABLEY Y,TABLEX X WHERE CLASS='计算机' AND SCORE <60 AND Y.CODE=X.CODE 3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果 SELECT Y.NAME,X.CLASS,X.SCORE FROM TABLEY Y,TABLEX X WHERE Y.CODE=X.CODE
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
INSERT INTO TABLEX(CODE,NAME,AGE)VALUES('97005','赵六','20')6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
UPDATE TABLEX SET AGE=21 WHERE CODE='97004'7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
DELETE FROM TABLEX WHERE CODE NOT IN(SELECT DISTINCT CODE FROM TABLEY)题目二、
有两个表定义如下:
create table individual (
firstname varchar2(20) not null
lastname vatchar2(20) not null
birthdate date
gender varchar2(1)
initial number(2)
farorite varchar2(6)
type varchar2(8)
); 在此表中建唯一索引 firstname + lastname
alter table individual
add constraint PK_individual unique (firstname , lastname )
create table chile_detail(
firstname varchar2(20)
lastname varchar2(20)
cname varchar2(8)
coment varchar2(2)
type varchar2(8)
);
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录
delete from individual where to_char(birthdate,'yyyy-mm-dd')='1990-10-02'2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”
update child_detail set cname='declear',coment='02' where type='kkd'
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
Select a.code,a.name,a.age,b.class,b.score From TableX a,TableY b Where a.name Like '张%' And a.CODE=b.CODE Order By a.Age desc2、请写出SQL,取出计算机科考成绩不及格的学生;
Select a.code,a.name,a.age,b.class,b.score From TableX a,TableY b Where b.score<60 And a.CODE=b.CODE
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
Select a.name,b.class,b.score From TableX a,TableY b Where a.CODE=b.CODE4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
Select a.name,b.class,b.score From TableX a,TableY b Where a.CODE(+)=b.CODE
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
Insert Into TableX (code,name,age) Values ('97005','赵六',20)
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
Update TableX Set Age=21 Where Code=97004
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
Delete From TableX Where Code Not IN (Select Code From TableY)
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录 Delete From Individual Where BrithDate=To_Date(‘1990-10-02’,’yyyy-mm-dd’);
2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”
Update chile_detail Set cname=’declear’,coment=02 Where type=’kkd’;
SELECT * FROM TableX WHERE Name LIKE '张%' ORDER BY Age;
2、请写出SQL,取出计算机科考成绩不及格的学生;
SELECT * FROM TableX x, TableY y WHERE x.Code = y.Code AND Class = '计算机' AND Score < 60;
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
SELECT x.Name, y.Class, y.Score FROM TableX x, TableY y WHERE x.Code = y.Code
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
Left Out:SELECT x.Name, y.Class, y.Score FROM TableX x, TableY y WHERE x.Code = y.Code(+)
Right Out: SELECT x.Name, y.Class, y.Score FROM TableX x, TableY y WHERE x.Code(+) = y.Code
Full Out:Left join union all right join
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
INSERT INTO TableX(Code, Name, Age) VALUES('97005','赵六',20);
COMMIT;6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
UPDATE TableX SET Age = 21 WHERE Code in (SELECT Code FROM TableX WHERE Name = '李五')
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
DELETE FROM TableX WHERE Code Not in (SELECT Code FROM TableY WHERE NVL(Score,0) = 0)
在此表中建唯一索引 firstname + lastname
CREATE UNIQUE INDEX NAME_UNINDEX ON individual(firstname,lastname)
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录
DELETE FROM individual WHERE TO_CHAR(birthdate,'YYYY-MM-DD') = '1990-10-02';
COMMIT;2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”
UPDATE chile_detail SET Cname = 'declear', coment = '02'
WHERE type = 'kkd';
COMMIT;
select * from tableX where name like '张%' order by age asc
2
select tableX.* from tableX left join tableY on tableY.code=tableX.code where tableY.class='计算机' and tableY.score<60select * from tableX where code in (select code from tableY where class='计算机' and score<60)3
select tableX.name,tableY.class,tableY.score from tableX,tableY where tableX.code=tableY.code4
select tableX.* from tableX left join tableY on tableY.code=tableX.code 5
请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
insert into TableX(code,name,age) values(97005,'赵六',20)6
李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新
update tableX set age=21 where name='李五'7
delete tableX where code not in (select code from tableY)
--前提是一条记录然而出生日期相同的人大有人在不止一个
delete individual where exists (select count(*) as num from individual where brithdate=to_date(1990-10-02,'yyyymmdd')
having num=1)
或者declare pl_sql
y where y.score!=null)
select * from tableX where name like '张%' order by age asc
2
select tableX.* from tableX left join tableY on tableY.code=tableX.code where tableY.class='计算机' and tableY.score<60select * from tableX where code in (select code from tableY where class='计算机' and score<60)3
select tableX.name,tableY.class,tableY.score from tableX,tableY where tableX.code=tableY.code4
select tableX.* from tableX left join tableY on tableY.code=tableX.code 5
请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
insert into TableX(code,name,age) values(97005,'赵六',20)6
李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新
update tableX set age=21 where name='李五'7
delete tableX where code not in (select code from tableY)
1.
select * from TabelX x,TableY y where x.code = y.code
and x.name like '张%' order by x.age asc
2.
select * from TabelX x,TableY y where
x.code=y.code and y.class='计算机'
and y.score<60
3.
select x.name,y.class,y.score from TabelX x,TableY y
where x.code=y.code
4.
select x.name,y.class,y.score from TabelX x,TableY y
where x.code=y.code(+)select x.name,y.class,y.score from TabelX x left join TableY y
on x.code=y.code 7.
select * from TabelX x where x.code not in (select y.code from TableY y)
SELECT * FROM X WHERE Name LIKE '%张' ORDER BY Age
2
SELECT * FROM Y WHERE Class ='计算机' AND Score <60
3
SELECT X.Name Y.Class Y.Score FORM X ,Y WHERE X.Code =Y.Code
4
SELECT X.Name Y.Class Y.Score FORM X FULL JION Y WHERE X.Code =Y.Code
5
INSERT INTO X (Code,Name,Age) VALUES('97005','赵六','20')
6
UPDATE X SET AGE='21' WHERE NAME='李五'
7
DELETE FROM X WHERE Code not in(SELECT CODE FROM X ,Y
WHERE Y.Score <>'' OR Y.Score IS NULL)
(select code from tabley where score is not null) ;
SELECT CODE FROM X WHERE NAME='李五';
有两个表: TableX有三个字段Code、 Name、 Age、 其中Code为主键;
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下:Code Name Age Code Class Score
97001 张三 22 97001 数学 80
97002 赵四 21 97002 计算机 59
97003 张飞 20 97003 计算机 60
97004 李五 22 97004 数学 55
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
select *
from tablex
where name like '张%'
order by age;
2、请写出SQL,取出计算机科考成绩不及格的学生;
select *
from tabley
where score < 60
and class = '计算机'
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
select x.name,y.class,y.score
from tablex x,tabley y
where x.code = y.code;
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
select x.name,y.class,y.score
from tablex x,tabley y
where x.code = y.code(+);
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
insert into tablex values(97005,'赵六',20);
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
update tablex
set age = 21
where code = 97004;
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
delete from tablex where code not in (select code from tabley);
题目二、
有两个表定义如下:
create tableindividual (
firstname varchar2(20) not null
lastname vatchar2(20) not null
birthdate date
gender varchar2(1)
initial number(2)
farorite varchar2(6)
type varchar2(8)
);在此表中建唯一索引 firstname + lastname
create unqiue index idx_name on tableindividual(firstname,lastname);create table chile_detail(
firstname varchar2(20)
lastname varchar2(20)
cname varchar2(8)
coment varchar2(2)
type varchar2(8)
);
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录
delete from tableindividual where to_char(birthdate,'yyyymmdd') = '19901002';2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”
update chile_detail set cname = 'declear',coment = '02' where type = 'kkd';
有两个表: TableX有三个字段Code、 Name、 Age、 其中Code为主键;
TableY有三个字段Code、 Class、Score, 其中Code + Class 为主键。两表记录如下:Code Name Age Code Class Score
97001 张三 22 97001 数学 80
97002 赵四 21 97002 计算机 59
97003 张飞 20 97003 计算机 60
97004 李五 22 97004 数学 55
1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;
2、请写出SQL,取出计算机科考成绩不及格的学生;
3、通过等值联接,取出Name、Class、Score,请写出SQL即输出结果
4、通过外联接,取出每个学生的Name、Class、Score、请写SQL输出结果
5、请写SQL,在TableX 表中增加一条学生记录(学号:97005 姓名:赵六 年龄:20);
6、李五的年龄记录错了,应该是21,请写SQL,根据主键进行更新;
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
题目二、
有两个表定义如下:
create tableindividual (
firstname varchar2(20) not null
lastname vatchar2(20) not null
birthdate date
gender varchar2(1)
initial number(2)
farorite varchar2(6)
type varchar2(8)
);在此表中建唯一索引 firstname + lastnamecreate table chile_detail(
firstname varchar2(20)
lastname varchar2(20)
cname varchar2(8)
coment varchar2(2)
type varchar2(8)
);
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录2、写一修改语句实现: 将表child_detail 中的type 为 “kkd” 的记录的Cname 值为“declear”,coment的值为“02”看似简单的题目,其实暗藏“陷阱”
比如
7、请写SQL,删除TableX中没有考试成绩的学生记录,请使用not in条件;
需求不明确,所以结果也有多个
(一)没有考试成绩的,在TableY中没有记录
delete from TableX code not in (select code from TableY)
(二)没有考试成绩的,在TableY有记录,只是没有分数(如:缺考的等),个人感觉这个更符合要求
delete from TableX code not in (select code from TableY where score is not null)
(三) 现实中,可能还有这种比较复杂的情况,假如,三门功课,只有一门有成绩,删不删除了?
1、写一个简单的SQL语句实现:删除表individual中一条出生日期(brithdate)为 1990年10月2日 出生的人的记录
--前提是一条记录然而出生日期相同的人大有人在不止一个
delete from individual where brithdate=to_date(1990-10-02,'yyyymmdd') and rownum=1
笔试时,一定要搞清楚题意在下笔呀!
顶,delete from tablex x where x.code not in(select y.code from tabley
y where y.score is not null;
1>select Name from TableX where Name like 'ÕÅ%' order by Age ASC2>select X.Name from TableX X left join TableY Y on X.code=Y.code where Y.class='计算机' and score<60
select Name from TableX where Code in(select code from TableY where Class='计算机'and Score<60)
3>select X.Name,Y.Class,Y.Score from TableX X join TableY Y on X.code=Y.code
select X.Name,Y.Class,Y.Score from TableX X, TableY Y where X.code=Y.code
4> select X.Name,Y.Class,Y.Score from TableX X full join TableY Y on X.code=Y.code 5>insert into TableX values(97005,'李五',20)6>update TableX set Age=21 where Code=(select code from TableX where Name='李五')7>delete from TableX where Code not in (select Code form TableY)