连接查询:
(1)内连接:inner join
(2)外连接: 左(外)连接 left join
右(外)连接 right join
全外连接 full join
(3)交叉连接 (笛卡尔积)
1.查询语句
(1)查询与“张志国”同一班级的学生信息(使用连接查询和子查询方式)。
select student2.sno,student2.sname,student2.ssex,
student2.s_class,student2.s_birth,student2.s_phone
from student_info as student1,student_info as student2
where student1.s_class=student2.s_class
and student1.sname='张志国'
and student2.sname<>'张志国';
select * from student_info
where s_class=(select s_class
from student_info where sname = '张志国')
and sname <> '张志国';
(2)查询比“计算机应用基础”学时多的课程信息(使用连接查询和子查询方式)。
select course2.cno,course2.cname,course2.ctime
from course_info as course1,course_info as course2
where course1.ctime>course2.ctime
and course1.cname='计算机应用基础';
select * from course_info
where ctime>(select ctime
from course_info where cname = '计算机应用基础');
(3)查询选修课程号为K002的学生的学号、姓名(使用连接查询、子查询、使用exists关键字的子查询)。
select student_info.sno,student_info.sname
from student_info ,work_info
where work_info.cno='K002'
and student_info.sno=work_info.sno;
select sno,sname
from student_info
where (sno in (select sno from work_info
where cno='K002'));
select sno,sname
from student_info
where exists (select * from work_info
where sno=student_info.sno
and cno='K002');
(4)查询没有选修K001和M001课程的学号、课程号和三次成绩(使用子查询)。
select sno,cno,score1,score2,score3
from work_info
where (sno not in (select sno from work_info
where cno='K001'
or cno='M001'));
2.数据操纵
(1)在学生表中添加一条学生记录,其中,学号为0593,姓名为张乐,性别为男,专业班级为电子05。
insert into student_info
values ('0593','张乐','男','电子05','','','');
(2)将所有课程的学分数变为原来的两倍。
update course_info
set c_score=2*c_score;
(3)删除张乐的信息。
delete from student_info where sname='张乐';
2870

被折叠的 条评论
为什么被折叠?



