题目一、
有两个表:
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 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.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 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 table chile_detail(
firstname varchar2(20)
lastname varchar2(20)
cname varchar2(8)
coment varchar2(2)
type varchar2(8)
);
有两个表:
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 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.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 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 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 individual to_char(brithdate,'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'