继前两次的实验,本次实验以熟练掌握利用select语句进行各种查询操作:单表查询、多表连接及查询、嵌套查询、集合查询等,巩固数据库查询操作。
下面就跟着小编一起练习吧!
在实验一创建并插入数据的表(Student, Course,SC,Teacher,TC)的基础上,完成以下操作。
(1)将教师‘罗莉'的名字改为‘罗莉莉'。
update Teacher set tname='罗莉莉' where tname='罗莉'
insert into Score(sno,cno,grade) values ('04261006','C003','64') insert into Score(sno,cno,grade) values('04261007','C004','79')
select sno 学号,cno 课程号,grade 分数from Score where sno=04261006 or sno=04261007;
delete from Score where sno=04261006 or sno=04261007;
CREATE TABLE average ( cno CHAR(8), avscore numeric(5,2), constraint a1 primary key (cno), constraint a2 foreign key (cno) references Course(cno), ) insert into average(cno,avscore) select distinct cno ,avg(grade) from Score group by cno
Update Student set 2014-year(Sbirth) 年龄 where Sname=' 马丽'
update Student set szipcode='221000'
update average set avscore='0'
delete from average where cno='C007'
delete from average;
create table tstudent ( Sno char(8) primary key, Sname varchar(8) unique ); Delete from tstudent where Sno like '001011%';
select sno 学号,sname 姓名from Student
select sno 学号,sname 姓名,sdept 系from Student
select * from Student
select sname 姓名,2014-year(sbirth) 年龄from Student
select sname 姓名,year(sbirth) 出生年份from Student
select distinct sno from Score select distinct student.sno from Student,Score where Student.sno=Score.sno and Score.grade>0 ;
select sno,sname from Student where sdept='计算机系'
select sname 姓名,2014-year(sbirth) 年龄from Student where 2014-year(sbirth)<23;
select distinct sno from Score where grade<60;
select sname 姓名,sdept 系,2014-year(sbirth) 年龄from student where 2014-year(sbirth) between 20 and 22;
select sname 姓名,sdept 系,2014-year(sbirth) 年龄from student where 2014-year(sbirth) not between 20 and 22;
select sname from Student where sdept='计算机系' or sclass='电商系'
select sname,sclass from Student where sclass not in('计','计'); (23)查询学号为“04262002”的学生的详细情况; [code]select student.sno,sname,ssex,2014-year(sbirth),sclass,grade from Student,Score where Student.sno=Score.sno and Student.sno='04262002';
select * from Student where sno like '04262%'
select sno 学号,sname 姓名,ssex 性别,2011-year(sbirth) 年龄from Student where sname like'王%'
select sno 学号,sname 姓名,ssex 性别,2011-year(sbirth) 年龄from Student where sname like '_田%'
select sname 姓名from Student where sname not like '刘%'
select cno,cname from Course where cno like 'C%05'
select Student.sno,sname,cno from Student,Score where Student.sno=Score.sno and grade is NULL;
select sno, cno from Score where grade is not NULL;
select sno ,sname from Student where sdept='计算机系' and 2014-year(sbirth)<22
select student.sno,grade from student,Score where Student.sno=Score.sno and cno='C001' order by grade desc;
select * from student order by sdept asc,2014-year(sbirth) desc;
select count(*) 人数from Student;
select count(distinct sno)人数from Score;
select sno,grade from Score where grade =(select max(grade)from Score )
select distinct a.* from Score a where a.sno IN (select top 1 Score.sno from Score where Score.cno = a.cno order by grade desc)
select max(grade)最高分数from Score where cno='C001'
select count(sno) 选课人数from Score group by cno;
select Student.sno,sname from Student where Student.sno in (select Student.sno from Student,Score where sdept='计算机系'and Student.sno=Score.sno group by Student.sno having count(cno)>=2);
select student.*,Score.grade from student ,Score where student.sno=Score.sno;
select a.cno,b.cpno from Course a,Course b where a.cpno=b.cno;
select sname,grade from student,Score where Student.sno=Score.sno and cno='C001' and grade>=90;
select Student.sno,sname,cname,grade from Course,Score,Student where Course.cno=Score.cno and student.sno=Score.sno;
select Sname from Student where not exists (select * from Course where not exists(select * from Score where Sno=Student.Sno and Cno=Course.Cno))
select student.sno,sname from student,Score where student.sno=Score.sno and cno='C001'; (46)查询选修了课程C001或C007的学生学号、姓名; [code]select student.sno,sname,cno from student,Score where student.sno=Score.sno and cno in ('C001','C007');[/code]
select sno ,sname,2014-year(sbirth) age ,sclass from student where sdept='计算机系' or 2014-year(sbirth)<=23;
select student.sno,sname from student,Score where student.sno=Score.sno and cno='C001' and student.sno in (select student.sno from student,Score where student.sno=Score.sno and cno='C007')
select student.sno ,sname,ssex,cname,2011-year(sbirth) age from student,Score,Course where student.sno=Score.sno and Score.cno=Course.cno and cname='数据库原理';
select sno,sname ,2014-year(sbirth) age from student where 2014-year(sbirth)<(select min(2014-year(sbirth)) from student where sclass='计61')and sclass !='计61';
select sno,sname,ssex,2014-year(sbirth) age from student where sdept=(select sdept from student where sname='夏天') and sname!='夏天'
create view view_student as select sno,sname,ssex,sbirth,sclass from student where sclass='13z网络'
create view view_student2 as select sno,sname,ssex,sbirth,sclass from student where sclass='13z网络' with check opthtml" target="_blank">ion;
create view v_cs_C001_student1 as select student.sno,sname,ssex,sbirth,sclass from Student ,Score where student.sno=Score.sno and sclass='13z网络' and cno='C001';
create view cs_c001_student2 as select student.sno,sname ,ssex,sbirth,sclass,cno from student,Score where student.sno=Score.sno and cno='C001' and sclass='13z网络'and student.sno in (select student.sno from student,Score where student.sno=Score.sno and grade>90)
create view v_birth_student as select sno,sname,2014-year(sbirth) age from student
create view v_female_student as select * from student where ssex='女';
create view v_average_student as select sno,avg(grade) avscore from Score group by sno;
select * from view_student where 2014-year(sbirth)<=22;
select * from v_cs_C001_student1;
update view_student set sname='王某某'where sno=04261001;
insert into view_student2(sno,sname,ssex,sbirth,sclass) values ('04262004','张某某','男','1987/11/09','计');
delete from view_student2 where sno='04262004'and sname='张某某';
实验课结束了,相信通过本节课的实践操作,小伙伴们都对数据库表的操作有了更进一步的了解。
以上就是查询数据库表的基本操作,几乎涵盖了各种查询操作所遇到的情况,值得大家亲自操作一下,相信对大家的学习有所帮助。
本文向大家介绍数据库表的查询操作(实验二),包括了数据库表的查询操作(实验二)的使用技巧和注意事项,需要的朋友参考一下 【实验目的】:了解SQL语言的使用,进一步理解关系运算,巩固数据库的基础知识。 【实验要求】:掌握利用Select语句进行各种查询操作:单表查询、多表连接及查询、嵌套查询、集合查询等。 【实验内容】 一、单表查询 1.简单查询 打开查询分析器,根建立teacher表,并加入数据。
本文向大家介绍YII2数据库查询实践,包括了YII2数据库查询实践的使用技巧和注意事项,需要的朋友参考一下 初探yii2框架,对增删改查,关联查询等数据库基本操作的简单实践。 数据库配置。 /config/db.php 进行数据库配置 实践过程中有个test库-》test表-》两条记录如下 sql 查询方式 yii2 提供了原始的数据库查询方式findBySql;同时, 通过占位符的方式,自动进行
我正在尝试检索一些值而不是其他值。事实上,我想通过用户的名字来搜索他们。 我尝试使用和,但找不到正确的解决方案。 如您所见,我还添加了。如果我不添加那个部分,它就不会检索任何东西。我想要的只是从我在TextField中所写的内容开始检索值。
我有一个firebase数据库,员工数据的结构如下。我还有一个用户表,它具有'Company ID'属性。每次用户登录时,我都希望获取与用户“公司ID”匹配的所有员工。是否有可能实现这使用firebase数据库规则或我必须写一些查询。
本文向大家介绍PHP实现对文本数据库的常用操作方法实例演示,包括了PHP实现对文本数据库的常用操作方法实例演示的使用技巧和注意事项,需要的朋友参考一下 PHP可以实现对文本数据库的数据的显示、加入、修改、删除、查询等五大基本操作。 我们以一个留言本程序为例,简述一下PHP实现对文本数据库的数据显示、加入、修改、删除、查询五大基本操作的方法。 此文本数据库共有字段10个:客户IP、发言时间、客户名、
本文向大家介绍python操作mongodb根据_id查询数据的实现方法,包括了python操作mongodb根据_id查询数据的实现方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了python操作mongodb根据_id查询数据的实现方法。分享给大家供大家参考。具体分析如下: _id是mongodb自动生成的id,其类型为ObjectId,所以如果需要在python中通过_id查询,