nosql练习题,nosql第二章课后题

SQL练习题

一 学生 – 课程数据库

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的铜梁网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

1 查询 7号课程没有考试成绩的学生学号

select sno from sc where cno=’7’ and grade is not null

2 查询 7号课程成绩在90分以上或60分以下的学生学号

select sno from sc where grade90 or grade60

3 查询课程名以“数据”两个字开头的所有课程的课程号和课程名。

Select cno,cname from c where cname like ‘数据%’

4 查询每个学生所有课程的平均成绩,输出学生学号、平均成绩

select sno,avg(grade) from sc group by sno

5 查询每门课程的选修人数,输出课程号、选修人数。

Select cno,count(*) from sc group by cno

6 查询选修 7号课程的学生的学号、姓名、性别。

Select s.sno, sname,ssex from s , sc where s.sno=sc.sno and cno = ‘7’

7 查询选修7号课程学生的平均年龄。

Select avg(sage) from s , sc where s.sno=sc.sno and cno = ‘7’

8 查询由30名以上学生选修的课程号。

Select sno from sc group by cno having count(*)30

9 查询至今没有考试不及格的学生学号

a: select sno from s where sno not in ( select sno from sc where grade60 )

b: select sno from sc group by sno having min(grade)=60

1 找出选修课程号为 C2 的学生学号与成绩。

Select sno,grade from sc where cno=’C2’

2 找出选修课程号为C4 的学生学号与姓名。

Select s.sno , sname from s,sc where s.sno=sc.sno and cno=’C4’

3 找出选修课程名为 Maths 的学生学号与姓名。

Select s.sno ,sname from s,sc,c

where s.sno=sc.sno and c.cno=sc.cno and cname = ‘Maths’

4找出选修课程号为C2或C4 的学生学号。

Select distinct sno from sc where cno in (‘C2’,’C4’)

或: Select distinct sno from sc where cno=’C2’ or cno =’C4’

5找出选修课程号为C2和C4 的学生学号。

Select sno from sc where cno =’C2’ and sno in (

select sno from sc where cno = ‘C4’ )

6 找出不学C2课程的学生姓名和年龄

select sname , sage from s where sno not in ( select sno from sc where cno=’C2’ )

或:

select sname , sage from s where not exists ( select * from sc where sc.sno=s.sno and cno=’C2’ )

7 找出选修了数据库课程的所有学生姓名。(与3同)

Select s.sno ,sname from s,sc,c

where s.sno=sc.sno and c.cno=sc.cno and cname = ‘数据库’

8 找出数据库课程不及格的女生姓名

嵌套:

select sname from s where ssex = ‘女’ and sno in ( select sno from sc where grade60 and cno in ( select cno from c where cname=’数据库’) )

连接:

Select sname from s,sc,c

where s.sno=sc.sno and c.cno=sc.cno and ssex=’女’ and cname = ‘数据库’ and grade60

9 找出各门课程的平均成绩,输出课程名和平均成绩

select cname , avg(grade) from sc , c where c.cno =sc.cno group by sc.cno

10找出各个学生的平均成绩,输出学生姓名和平均成绩

select sname , avg(grade) from s , sc where s.sno=sc.sno group by sc.sno

11 找出至少有30个学生选修的课程名

select cname from c where cno in ( select cno from sc group by cno having count(*)=30 )

12 找出选修了不少于3门课程的学生姓名。

Select sname from s where sno in ( select sno from sc group by sno having count(*)=3)

13 找出各门课程的成绩均不低于90分的学生姓名。

Select sname from s where sno not in ( select sno from sc where grade90)

14* 找出数据库课程成绩不低于该门课程平均分的学生姓名。

Select sname from s where sno in (

Select sno from sc , c where sc.cno=c.cno and cname=’数据库’ and

Grade (Select avg(grade) from sc , c where sc.cno=c.cno and cname=’数据库’ ) )

15 找出各个系科男女学生的平均年龄和人数。

Select sdept,ssex , avg(sage) , count(*) from s

Group by sdept , ssex

16 找出计算机系(JSJ)课程平均分最高的学生学号和姓名。

Select sc.sno , sname from s, sc where s.sno=sc.sno and sdept=’JSJ’

Group by sc.sno Having avg(grade) =

( Select top 1 avg(grade) from sc, s where s.sno=sc.sno and sdept=’JSJ’

group by sc.sno order by avg(grade) DESC )

三 客户 – 商品数据库中包括3按各表:KH,FP,YWY

1 查询工资在 1000 到3000 元之间的男性业务员的姓名和办公室编号。

Select Yname , Ono from YWY where salary between 1000 and 3000 and Ysex=’男’

2 查询各个办公室的业务员人数,输出办公室编号和对应的人数。

Select Ono , count(*) from YWY group by Ono

3 查询每个客户在2002年5月购买的总金额,输出客户号和相应的总金额。

Select Kno,sum(Fmoney) from FP where fdate between ‘2002.5.1’ and ‘2002.5.31’

Group by Kno

4 查询2002年5月购买次数超过5次的所有客户号,且按客户号升序排序。

Select Kno from FP where fdate between ‘2002.5.1’ and ‘2002.5.31’

Group by Kno having count(*)5

Order by Kno ASC

5 查询各办公室男性和女性业务员的平均工资。

Select Ono,Ysex ,avg(salary) from YWY group by Ono , Ysex

6 查询2002年5月曾经在王海亮业务员手中购买过商品的客户号、客户姓名、联系电话。

Select Kno,Kname,phone from KH where Kno in (

Select kno from FP where fdate between ‘2002.5.1’ and ‘2002.5.31’ and

Yno=(select Yno from YWY where Yname = ‘王海亮’ )

7 查询所有工资比1538号业务员高的业务员的编号、姓名、工资。

Select yno ,Yname, salary from YWY where salary

( Select salary from YWY where Yno=’1538’ )

8 查询所有与1538号业务员在同一个办公室的其他业务员的编号、姓名。

Select Yno , Yname from YWY where Yno’1538’ and Ono in (

Select Ono from YWY where Yno=’1538’ )

9 查询销售总金额最高的业务员的编号。

Select Yno from FP Group By Yno Having sum(Fmoney) =

(Select top 1 sum(Fmoney) from FP group by Yno ORDER BY sum(Fmoney) DESC)

10 查询所有业务员的编号、姓名、工资以及工资比他高的其他业务员的平均工资。

利用自身连接

Select y1.Yno ,y1.Yname ,y1.salary , avg( y2. salary) from YWY y1 , YWY y2

Where y1.Ynoy2.Yno and y1.salary y2.salary

Group by y1.Yno

Sno salary sno salary

1 100 1 100

2 120 2 120

3 90 3 90

4 110 4 110

四 某中学数据库中由一张表:

学生选课表:由板及代码、班内学号、姓名、科目、成绩五个属性组成,关系模式为

SC(BJDM,BNXH,XSXM,KM,CJ) ,其中(BJDM,BNXH)为主码。

说明:每个学生每门科目存放一个记录,科目有“语文”、“数学”、“外语”三门。

1 找出每个班级的班级代码、学生人数、平均成绩。

Select BJDM,count(*) ,avg(CJ) from SC group by BJDM

2 找出每个学生的班级代码、学生姓名、考试科目数、总成绩。

Select BJDM,XSXM,count(*) , sum(CJ) from SC

Group by BNXH

3 输出一张表格,每位学生对应一条记录,包括:班级代码、姓名、语文成绩、数学成绩、外语成绩。

方法一:利用视图

create view v1 (bjdm,xsxm, yw,sx,wy ) AS

select bjdm , xsxm , cj , 0,0 from sc where km=’语文’

union

select bjdm , xsxm , 0 , cj,0 from sc where km=’数学’

union

select bjdm , xsxm , 0,0,cj from sc where km=’外语’

select bjdm, xsxm , sum(yw) as 语文, sum(sx) as 数学, sum(wy) as 外语 from v1 group by bjdm, xsxm

方法二:自身连接

select a.bjdm,a.xsxm , a.km,a.cj , b.km,b.cj , c.km,c.cj from sc a , sc b , sc c

where a.bjdm=b.bjdm and a.bnxh= b.bnxh and b.bjdm=c.bjdm and b.bnxh= c.bnxh

and a.km=’语文’ and b.km=’数学’ and c.km=’外语’

方法三:利用存储过程(略)

4 输出一张表格:由成绩低于60分的每位学生对应一条记录,包括字段:班级代码、姓名、最低成绩。

Select bjdm,xsxm ,min(CJ) from sc where grade60 group by bjdm,xsxm

5输出一张表格:由成绩低于60分的每位学生对应一条记录,包括字段:班级代码、姓名、最高成绩、平均成绩。

得到平均成绩:create view V1 (bjdm,bnxh ,avg_cj) AS

select bjdm,bnxh ,avg(cj) from sc where bjdm , bnxh

select sc.bjdm,sc.xsxm ,max(cj) , avg_cj from sc , V1

where sc.bjdm=v1.bjdm and sc.bnxh=V1.bnxh and cj60

group by sc.bjdm,sc.xsxm

6输出一张表格:所有成绩不低于60分的每位学生对应一条记录,包括字段:班级代码、姓名、平均成绩。

select bjdm, xsxm , avg(cj) from sc

where sno not in ( select sno from sc where grade60)

group by bjdm, xsxm

7输出一张表格:每一位学生对应一条记录,包括字段:班级代码、姓名、去掉一个最低分后的平均成绩。

方法一:

得到每个学生的最低分:

create view V1 (bjdm,bnxh ,min_cj) as

select bjdm,bnxh,min(cj) from sc group by bjdm,bnxh

select sc.bjdm,sc.xsxm , avg(cj) from sc , v1

where sc.bjdm=v1.bjdm and sc.bnxh=v1.bnxh and sc.cj v1.min_cj

group by bjdm,bnxh

方法二:

select sc.bjdm,sc.xsxm , ( sum(cj) – min(cj) ) / count(*) from sc

group by bjdm , bnxh

8输出一张表格:每门科目对应一条记录,包括字段:科目、去掉一个最低分后的平均成绩。

方法一:

得到每门课的最低分:

create view V1 ( km, min_cj) as

select km,min(cj) from sc group by km

select sc.km , avg(cj) from sc , v1

where sc.km=v1.km and sc.cj v1.min_cj

group by sc.km

方法二:

select km , (sum( cj) – min(cj) )/count(*) from sc

group by km

补充9:输出表格:每门科目对应一条记录,包括字段:科目、去掉一个最低分和最高分后的平均成绩。

select km , (sum( cj) – min(cj) – max(cj) )/count(*) from sc

group by km

五 数据库存放着某高校1990年以来英语四、六级的考试情况,且规定:

1 英语四、六级考试每年分别在6月和12月举行二次;

2 四级没有通过的学生不能报考六级;

3 某一级的考试只要没有通过可以反复参加考试;

4 某一级的考试一旦通过就不能再报考同级的考试;

5 允许报了名但不参加考试。

该数据库中有二张表,相应的关系模式如下:

学生表:S(Sno, Sname, Ssex, Sage, Sdept),其中Sno为主码。

考试表:E(Sno, Year, Month, Level, Grade),学号、年、月、级别、成绩。

其中(Sno, Year, Month)为主码。

1. 找出各次四级和六级考试的参考人数和平均成绩(报了名但没有参加考试的不作统计)

select year , month,level ,count(*) , avg(grade)

group by year,month , level

2. 找出各次四级考试中平均分最高的系科(报了名但没有参加考试的不作统计)。

A: Select sdept from s , e where s.sno=e.sno

Where level=4

Group by sdept

Having avg(grade)=ALL(

Select avg(grade) from s , e where s.sno=e.sno where level=4 Group by sdept )

B: Select top 1 sdept from s , e where s.sno=e.sno

Where level=4

Group by sdept

Order by (avg(grade) desc

3. 找出已经通过英语六级考试的学生的学号、姓名和性别(用连接方法做)

select s.sno,sname,ssex from s,e

where s.sno=e.sno and level=6 and grade=60

4. 找出在同一年中四、六级考试都参加了的学生的学号

1) select sno from E

where (level=4 and grade=60) or level=6

group by year having count(*)=2

2) select sno from E X where level=4 and grade=60 and exists (

select * from E Y where Y.sno=X.sno and year=X.year and level=6 )

5. 找出只参加一次考试就通过了英语六级考试的学生的学号

select sno from E

where level=6

group by sno

having count(*)=1 错,想想为何?

1) select sno from E

where level=6

group by sno

having count(*)=1 and max(grade)=60

2) select sno from E where level=6 and grade=60 and sno in (

select sno from E where level=6 group by sno having count(*)=1)

6. 找出至今没有通过英语四级考试的学生的学号(应包括至今还没有参加过考试或者是参加了但还没有通过两种)

select sno from E where level=4

group by sno

having max(grade)60

Union

Select sno from s where sno not in( select sno from E)

7. 找出英语六级考试中合格人数最少的考试年份和月份(有并列的都要列出,用一句SQL语句)。

Select year , month From E

Where level = 6 and grade=60

Group by year , month

Having count(*) =all

(Select count(*) from E where level=6 and grade=60 group by year , month )

我是从“上海全鼎软件学院”毕业的————————

SQL数据库练习题

1. SQL Server 2000是典型的关系型数据库产品。 ( 1 )

2. 在一台计算机上可以同时运行多个版本的SQL Server。 ( 1 )

3. 在SQL Server中日志文件是维护数据库完整性的重要工具。 ( 0 )

4. 在定义数据表时,定义某列为标识列的关键字是Identity。 ( 1 )

5. 浮点数据类型的优点是能够存储范围非常大的数字,但容易发生误差。 ( 0 )

6. 数据库完整性的目的是为了防止错误信息输入和输出。 ( 0 )

7. 在Update语句中,一次可以更新多个表。 ( 0)

8. 尽量使用Select * ,可以加快查询速度。 ( 0 )

9. 在SQL Server 2000中表示注释可以用类似C语言的/*...*/和//。 ( 0 )

10. 在SQL Server中,RTRIM函数删除字符串右边的空白字符。 ( 1 )

11. 一个表只能有一个聚集索引(簇索引)。 ( 1 )

12. SQL查询语言中,如果没有指定排序方式,则默认是升序方式。 ( 1 )

13. 在SQL Server 2000中ntext类型的字段不能进行排序操作。 ( 0 )

14. 在SQL Server 2000中bit类型的字段不能建立索引。 ( 1 )

15. 在被定义为唯一索引的列上的数据不能有重复的值。 ( 1 )

16. 在被定义为唯一索引的列上的数据不允许空。 ( 0可以的但是只能有一个null值 )

17. 在SQL Server中,每张表都应该建立一个索引,以提高查询速度。 ( 0 )

18. 视图在SQL Server中是一张虚拟表。 ( 1 )

19. 当一个视图由2个以上基本表构成时,不能进行删除视图中的数据。 ( 0 )

20. 在SQL Server中,触发器是一种特殊的存储过程。 ( 1 )

21. 由于存储过程是解释执行,所以每次执行时都要检查是否有语法错误。 ( 0 )

22. 可以在用户正在使用的数据库上执行数据库恢复操作。 ( 0 )

1表示正确

SQL触发器练习题求解

Create TRIGGER 成绩表_TRIG ON 成绩表 FOR INSERT , UPDATE

AS

BEGIN

SET NOCOUNT ON

Declare @InsertedCount Int

Declare @DeletedCount Int

Set @InsertedCount = (Select Count(*) From Inserted)

Set @DeletedCount = (Select Count(*) From Deleted)

If (@InsertedCount0) Begin

UPDATE 成绩表 SET 成绩表.总评 = 成绩表.平时成绩 + 成绩表.期中成绩 + 成绩表.期末成绩 From Inserted Where 成绩表.学号=Inserted.学号

End

If (@DeletedCount0) Begin

UPDATE 成绩表 SET 成绩表.总评 = 成绩表.平时成绩 + 成绩表.期中成绩 + 成绩表.期末成绩 From Deleted Where 成绩表.学号=deleted.学号

End

SET NOCOUNT OFF

END

用sql语句创建一个教师表教师可以带多个班但不能带多门课

热门频道

首页

博客

研修院

VIP

APP

问答

下载

社区

推荐频道

活动

招聘

专题

打开CSDN APP

Copyright © 1999-2020, CSDN.NET, All Rights Reserved

sql

打开APP

SQL数据库创建学生、教师、选课表 原创

2020-12-17 12:05:09

7点赞

Chowhound_i

码龄2年

关注

SQL数据库创建学生、教师、选课表

创建学生表

create table student (

sno char(14) primary key,

sname char (10) not null,

ssex char(2),

sage tinyint,

sdept varchar(20),

spassword tinyint,

)

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

创建教师表

create table teacher (

tno char(14) primary key,

tname char (10) not null,

tsex char(2),

tage tinyint,

sdept varchar(20),

spassword tinyint,

)

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

创建选课表

create table course (

cno char(10),

sno char(14) not null,

tno char(14) not null,

cyear tinyint,

cterm tinyint,

grade tinyint,

primary key(sno,tno),

foreign key(sno) references student(sno),

foreign key(tno) references teacher(tno),

)

1

2

3

4

5

6

7

8

9

10

11

1

2

3

4

5

6

7

8

9

10

11

文章知识点与官方知识档案匹配

MySQL入门技能树使用数据库创建和删除表

28046 人正在系统学习中

点击阅读全文

打开CSDN,阅读体验更佳

3.SQL--创建教师表和向表内插入数据_weixin_33712881的博客

3.SQL--创建教师表和向表内插入数据 --创建教师表,并向表内插入数据 create table Teacher(Tid varchar(10),Tname nvarchar(10)) --向表内插入数据 insertinto Teacher values('01' , '韩寒') insert into Teacher values('02...

sql语句(学生表、课程表、分数表、教师表)_煜帆帆的博客

student(学生表)、teacher(教师表)、course(课程表)、sc(分数表) 2、创建表 //学生表 create table student( sno varchar2(10) primary key, sname varchar2(20), sage number(2), ssex varchar2(5) ); 1 2 3 4 5 6...

热门推荐 创建一个数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)

创建一个数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表… 表(一)Student (学生表) 属性名 数据类型 可否为空 含 义 Sno varchar (20) 否 学号 Sname varchar (20) 否 学生姓名 Ssex varchar ...

继续访问

mysql创建教师表_day34 mysql 认识数据库,创建学生,教师,学院表

数据库 - 数据的仓库(集散地) - database - 实现数据持久化和数据管理持久化 - 将数据从内存转移到能够长久保存数据的存储介质的过程数据库的分类:关系型数据库(SQL)和非关系型数据库(NoSQL)文件系统 / 层次数据库 / 网状数据库关系型数据库1970s - E.F.Codd - IBM研究员 - System R理论基础:关系代数和集合论具体表象:用二维表来保存数据 - 学生...

继续访问

使用SQL语句创建及使用SQLServer数据库_MyAnqi的博客

1使用SQL语句在数据库中Student表插入对应表格前2行元组。 insert into Student(sno,sn,sex,bor,clano,age)values(108,'曾华','男','1992-09-01','09033',22); insert into Student(sno,sn,sex,bor,clano,age)values(105,...

...名学生的SQL语句。_白一晓的博客_查询教师表中的总人数

在Mysql面试的写SQL语句环节中,有人曾碰到了这样一道这样的一道SQL语句题。目前有两张数据表,一张学生,一张老师表。里面都有Name和Code两个字段。求出张三的老师一共有多少名学生。 这样,我们还是先建两张普通的数据表。

最新发布 mysql 创建学生表、课程表、学生选课表

学生-课程数据库中包含以下三个表关系的主码加粗表示,各个表中的数据实例:StudentCourseSCSno为Student表的主键,Cno为Course表的主键,SC表中外键Sno,Cno分别是Student表和Course表的主键

继续访问

数据库实验报告一

KingBase数据库下SQL语句的基本使用

继续访问

数据库sql语句练习_Young_991的博客

一、设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示。用SQL语句创建四个表并完成相关题...

...和MySQL示例查询_库特社区的博客_sql创建教师信息表

了解如何在其中创建表是一个重要且基本的概念。SQL 在本教程中,我将使用 PostgreSQL 和 MySQL 的代码示例向您介绍语句的语法。SQLCREATE TABLE 基本语法CREATE TABLE 以下是该语句的基本语法:CREATE TABLE ...

【SQL】基本SQL数据表(学生、老师、课程、成绩)

create table student--创建student数据表 ( s_no char(10) not null, --学号 s_name nchar(10), --姓名 s_sex char(2), --性别 borndate smalldatetime,--出生日期 ClassName nvarchar(50), --班级名称 Telephone varchar(11), --电话号码 EnrollDate smal.

继续访问

数据库题:学生表,选课表,课程表写SQL(多表)

设教学数据库中有三个基本表: 学生表 S(SNO,SNAME,AGE,SEX),其属性表示学生的学号、姓名、年龄和性别;选课表 SC(SNO,CNO,GRADE),其属性表示学生的学号、所学课程的课程号和成绩;课程表 C(CNO,CNAME,TEACHER),其属性表示课程号、课程名称和任课教师姓名。 下面的题目都是针对上述三个基本表操作的(原题S#、C#这样子写法在查询的时候会报错,这里就用S...

继续访问

2021-09-06

#创建db_test数据库 create DATABASE db_test CHARACTER set utf8; use db_test; #在test数据库中创建teacher表 create table teacher( number int PRIMARY key auto_increment, tname VARCHAR(30), sex VARCHAR(4), depno int, salary float, address VARCHAR(...

继续访问

太原理工大学软件学院数据库实验四(2021.4.26)

太原理工大学软件学院数据库实验四(2021.4.26) -- (1)创建Student 表 CREATE TABLE Student ( Sno CHAR(8) PRIMARY KEY, Sname CHAR(8) NOT NULL, Ssex CHAR(2) CHECK( Ssex in ('男','女')), Sage SMALLINT, Sdept CHAR(20), Sclass CHAR(4) NOT NULL, Stotal smallint DEFAULT 0 ); -- (2)创建Cours

继续访问

SQL语言编程实战系列(一)——教学管理数据库的创建和简单操作

SQL语言编程实战系列(一)——教学管理数据库的创建和简单操作,基于《数据库原理与设计——基于SQL Server2012》王世民等编著P204-综合题5.3.1编写的解答。

继续访问

SQL建表语句(建立学生_课程数据库)

SQL建表语句(建立学生_课程数据库) (1)建立学生_课程数据库 (2)包含学生表Student 包含Sno(学号),Sname(姓名),Ssex(性别),Sage(年龄),Sdapt(所在系)属性列 学号为主码(主键) (3)创建课程表Course 包含Cno(课程号),Cname(课程名),Cpno(先行课课程号),Credit(学分)属性列 课程号为主码(主键) (4)学生_课程表SC 包含Sno(学号),Cno(课程号),Grade(成绩)属性列 学号,课程号为主码(主键) Creat

继续访问

Oracle完整的试题

[code="java"]create table student( sno varchar2(10) primary key, sname varchar2(20), sage number(2), ssex varchar2(5) ); create table teacher( tno varchar2(10) primary key, tname varchar2(20) ...

继续访问

用mysql创建学生成绩表_用SQL创建学生成绩数据库

创建数据库school,这个数据库中包含四个表:分别是学生表、教师表、课程表和成绩表。语法:create database school;(创建数据库school)show databases;(查看是否已经创建好)drop database school;(删除数据库school,这里不必删除)2.设计创建学生表、教师表、课程表和成绩表。语法:use school;create table st...

继续访问

数据库面试----学生、老师、课程、选课表常用sql示例

数据库面试----学生、老师、课程、选课表常用sql示例 请先看看六大范式详解 1——建表 (1)学生表 student DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `sid` int(11) DEFAULT NULL, `sname` varchar(20) DEFAULT NULL, `sage` int(11) DEFAULT NULL, `ssex` varchar(20) DEFAULT NULL ) ENGIN

继续访问

创建学院表 学生表 教师表 课程表 选课记录表

为什么要使用数据库 解决数据持久化问题 高效的管理数据(增删改查) 数据库的分类: 关系型数据库 理论基础:关系代数 具体表象:二维表 行:记录 列:字段 编程语言:SQL(结构化查询语言) DDL - 数据定义语言 — create / drop / alter DML - 数据操作语言 — insert / delete / update DQL - 数据查询语言 — select DCL - 数据控制语言 — grant / revoke ...

继续访问

将数据插入教师表.sql

sql 插入多条语句

合肥工业大学—SQL Server数据库实验三:SQL语句创建和删除基本表

SQL语句创建和删除基本表1. 编写6个基本表2. 修改基本表结构,完整性约束条件3. 用Drop table 语句删除基本表 1. 编写6个基本表 设有简单教学管理的6个关系模式如下: 系(系编号,系名称、系主任、联系电话、地址) 专业(专业编号、专业名称、所属系) 教师(教师编号、姓名、所在系、电话、电子信箱) 学生(学号、姓名、性别、出生日期、所学专业) 课程(课程号、课程名、学分、先修课) 学生选课(学号、课程号、成绩) 要求:在数据库EDUC中,创建对应的6个基本表,基本表的名称和属性名称由

继续访问

学习好sql

科目表 Course数据表介绍 --1.学生表 Student(SId,Sname,Sage,Ssex) --SId 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 --2.课程表 Course(CId,Cname,TId) --CId 课程编号,Cname 课程名称,TId 教师编号 --3.教师表 Teacher(TId,Tname) --TId 教师编号,Tna...

继续访问

CSDN学霸课表——NoSQL是什么

《NoSQL是什么》 NoSQL(NoSQL = Not Only SQL),意即反SQL运动,是一项全新的数据库革命性运动。NoSQL的拥护者们提倡运用非关系型的数据存储,相对于目前铺天盖地的关系型数据库运用,这一概念无疑是一种全新的思维的注入。 ►阅读全文 Redis集群架构讲师:李兴华 Redis是现在使用最为广泛的NoSQL数据库技术,其自身不仅拥有着良好的操作性能,也被广

继续访问

MySQL的teaching表建立_MySQL-一- 创建数据表

问题一:如何验证MySQL数据库安装成功?问题二:如何用客户端navicat连接到MySQL数据库?练习:创建学校数据库的表2.创建数据库2.1 创建学生表student2.2创建成绩表score2.3创建课程表course2.4创建教师表 teacher注:这里教师姓名可以为null3.练习插入数据3.1 向学生表里添加数据3.2向成绩表中添加数据3.3向课程表中添加数据3.4向教师表中添加数据...

继续访问

学生选课在MYSQL创建表_设要建立“学生选课”数据库,库中包括学生、课程和选课 3 个表,其表结构为: 学生(学号,姓名,性别,年龄,所在系) 课程(课程号,课程名,先行课) 选课(学号,课程号,成...

【单选题】湿空气的下列参数:I.干球温度、II.湿球温度、III.露点温度,它们之间的大小关系是【填空题】在缺省情况下,所创建的索引是_________索引。【其它】使用 T-SQL 命令,完成下面的操作。 1 .创建学生成绩视图(学号,姓名,课程编号,课程名称,成绩) 。 2 .创建信息系学生视图(学号,姓名,性别,系名,出生日期,民族,总学分,备注)。 3 .创建优秀学生视图(学号,姓名,平均...

继续访问

用sql语句创建一个教师表

sql

写评论

评论

35

7

分享

前往CSDN APP阅读全文

阅读体验更佳

CSDN

成就一亿技术人

前往

Chrome浏览器

继续

打开CSDN APP阅读体验更佳

sql语句相关测试

sql语句相关测试

篇一:SQL语句测试

1、(10分)要求:

选择受理时间在2008-5-1 到 2008-6-1之间的所有申请人姓氏为“刘”的数据,并把“新受理编号”列表示成当前机器时间的年月和原受理编号年月后的数值组合

格式如下:

受理编号,新受理编号,受理时间, 申请人

200801112 201008112 2008-01-13刘XX

需要的表

I_Optinst 业务实例表

REGDATE(受理日期)

Regnum(受理编号)

Proposer(申请人)

解答:select Regnum as 受理编号, as 新受理编号,REGDATE as 受理时间,Proposer as申请人 from Optinst 2、(15分)要求:

前提:只统计业务小类“存量房买卖”

①按照月份分12月列出2008年每个月份的月份对应月份的交易总面积

②按照月份分12月列出2008年每个月份的月份对应月份的交易均价(申报价格/建筑面积)

格式

年度月份 交易总面积 年度月份交易均价(元/平方米)

2008-01 23232 2008-01 2323

2008-02 23232008-02 232

2008-03 232323 2008-03 7656

2008-04 232323 2008-03 565

2008-05 232323 2008-03 5656

2008-06 232323 2008-03 565

2008-07 232323 2008-03 67

2008-08 232323 2008-03 676

2008-09 232323 2008-03 6767

2008-10 232323 2008-03 8686

2008-11 232323 2008-03 867

2008-12 232323 2008-03 454

需要的表:

Fc_room 房间表

BAREA(建筑面积)

I_Optinst业务实例表

regdate(受理时间)

fc_owner 产权表

COSTVAL(申报价格)

EVLVAL(评估价格)

fc_owoom 房间明细表

1.select regdate as年度月份,BAREA as 交易总面积 from Fc_room,Optinst where

3、(20分)要求:

①:按照时间统计收费明细 统计格式如下

受理编号缴费人收费日期 收费名称收费金额核费人收费人

②:按照时间汇总(2008年度)统计收费项目分类 统计格式如下

收费名称 总金额

需要的表:

I_OptInst(业务实例表)

Regnum 受理编号

Proposer 申请人

I_Charge(收费实例表)

HEFEIMAN 核费人

PAYEE 收款人

CDATE 收费日期

I_ChrDtl(收费实例明细表

CNAME 收费名称

MONEY 收费金额

4、(15分)要求:用途是住宅并且建筑面积=140140 定义为 “非普通住宅”

用途是商业并且建筑面积140 定义为 “商业A级”

其他情况定义为“非住宅”

根据用途和面积列表出所有数据

格式

受理编号, 用途

200406000386 普通住宅

200406004631 非普通住宅

200406004633 普通住宅

200406004638 普通住宅

200406004641 非住宅

200501000004 普通住宅

200406004568 非住宅

200406005677 商业A级

表:

fc_room

barea 建筑面积

BUse 用途

i_optinst

regnum 受理编号

5、(30分)工作量统计

① 选择出以下格式的数据;并创建视图名称为view_AAAA

业务小类业务实例 交易价格建筑面积 登记时间

1 存量房买卖 14100 19400.0029.98 2005-11-10 11:32:50 2 新建商品房 15041 229530.00 124.07 2005-11-21 08:59:36 3 新建商品房 15043 177363.00 101.35 2005-11-21 09:15:59 4 新建商品房 13046 71130.0023.71 2005-11-02 10:15:37 5 新建商品房 11280 148563.00 87.39 2005-10-11 09:50:48 6 新建商品房 11353 267369.00 116.04 2005-10-11 15:34:53 7 房改售房 2689 35.22 2004-06-17 08:43:00 8 产权人名称变更 11701 724.18 2005-10-17 10:05:20 9 新建商品房 7206 158257.00 88.69 2005-09-16 14:50:57 10 存量房买卖 (转 载于: 博 威范文 网: sql语句测试 )10100 103.07 2005-08-31 20:27:06 11 存量房买卖 12980 51500.0046.66 2005-11-01 14:41:32 12 新建商品房 13000 136782.00 80.46 2005-11-01 15:37:05 13 新建商品房 16946 300844.00 146.33 2005-12-15 14:15:07 14 存量房买卖 10091 509.18 2005-08-31 19:19:25 ② 使用视图 view_AAAA 当做表 选择出如下样式数据

业务小类 件数合计金额 合计面积

1 用途变更 1151.3

2 转移登记 184.03

3 新建商品房 31 263243643197.34

4 房改售房 8252.43

5 产权人名称变更 3 778.6

6 单位产新建 311697.49

7 赠与 1 28.48

8 存量房买卖 24 4379004134.67

9 判决仲裁 2 439.41

10 继承遗赠 1 49.17

11 换证 2 228.88

12 新建房屋 17 928.91

③ 用水晶报表关联视图 view_AAAA 设计出类似于②的数据格式 需要的表

FC_Owner

EvlVal交易价格

I_OptInst,

SOName 业务小类

fc_owoom,

BArea 建筑面积

FC_Room

regdate 受理日期

篇二:sql查询语句学习测试答案

第一部分SQL查询语句的学习

单表查询 1、--查询订购日期在1996年7月1日至1996年7月15日之间的订单的订购日期、订单ID、客户ID和雇员ID等字段的值

use eee

SELECT 订购日期,订单ID,客户ID,

雇员ID

FROM 订单

WHERE 订购日期BETWEEN '1996-7-1 00:00:00' AND '1996-7-15 23:59:59'

2、--查询“Northwind”示例数据库中供应商的ID、公司名称、地区、城市和电话字段的值。条件是“地区等于华北”并且“联系人头衔等于销售代表”。

use eee

SELECT 供应商ID,公司名称,地区,城市,电话

FROM 供应商

WHERE 地区='华北' AND 联系人职务='销售代表'

3、--查询“Northwind”示例数据库中供应商的ID、公司名称、地区、城市和电话字段的值。其中的一些供应商位于华东或华南地区,另外一些供应商所在的城市是天津 use eee

SELECT 供应商ID,公司名称,地区,城市,电话

FROM 供应商

WHERE 地区IN('华东', '华南') OR 城市='天津'

4、--查询“Northwind”示例数据库中位于“华东”或“华南”地区的供应商的ID、公司名称、地区、城市和电话字段的值

use eee

SELECT 供应商ID,公司名称,地区,城市,电话

FROM 供应商

WHERE 地区IN('华东', '华南')

多表查询 5、--查询订购日期在1996年7月1日至1996年7月15日之间的订单的订购日期、订单ID、相应订单的客户公司名称、负责订单的雇员的姓氏和名字等字段的值,并将查询结果按雇员的“姓氏”和“名字”字段的升序排列,“姓氏”和“名字”值相同的记录按“订单 ID”的降序排列

use eee

SELECT 订购日期,订单ID,公司名称,姓氏,名字

FROM 订单,雇员,客户

WHERE 订购日期BETWEEN '1996-7-1 00:00:00' AND '1996-7-15 23:59:59'

AND 订单.雇员ID = 雇员.雇员ID

AND 订单.客户ID = 客户.客户ID

ORDER BY 姓氏,名字ASC,订单ID DESC

6、--查询“10248”和“10254”号订单的订单ID、运货商的公司名称、订单上所订购的产品的名称

use eee

SELECT 订单.订单ID,公司名称,产品名称

FROM 订单,运货商,产品,订单明细

WHERE 订单.订单ID IN('10248','10254')

AND 订单.订单ID = 订单明细.订单ID

AND 订单明细.产品ID = 产品.产品ID

AND

订单.运货商= 运货商.运货商ID

7、--查询“10248”和“10254”号订单的订单ID、订单上所订购的产品的名称、数量、单价和折扣

use eee

SELECT 订单.订单ID,产品名称,数量,订单明细.单价,折扣

FROM 订单,产品,订单明细

WHERE 订单.订单ID IN('10248','10254')

AND 订单.订单ID = 订单明细.订单ID

AND 订单明细.产品ID = 产品.产品ID

篇三:sql语句练习题及答案

一 在数据库 school 中建立student , sc, course 表。

学生表、课程表、选课表属于数据库 School ,其各自的数据结构如下:

学生 Student (Sno,Sname,Ssex,Sage,Sdept)

课程表 course(Cno,Cname,Cpno,Ccredit)

学生选课 SC(Sno,Cno,Grade)

二 设定主码

1 Student表的主码:sno2 Course表的主码:cno 3 Sc表的主码:sno,cno

1写出使用 Create Table 语句创建表 student , sc, course 的SQL语句

2

3 删除student表中的元组

4在数据库school中删除关系student

5在student表添加属性sbirthdate 类型 datetime

Delete

1 删除所有 JSJ 系的男生 from Student where Sdept=’JSJ’ and Ssex=’男’; 2 删除“数据库原理”的课的选课纪录

from SC where Cno in (select Cno fromCourse where Cname=’数据库原理’);

Update

1 修改 0001 学生的系科为: JSJ

2 把陈小明的年龄加1岁,性别改为女。 2 修改李文庆的1001课程的成绩为 93 分 3 把“数据库原理”课的成绩减去1分

Select 查询语句

一 单表

1查询年龄在19至21岁之间的女生的学号,姓名,年龄,按年龄从大到小排列。 2查询姓名中第2个字为“明”字的学生学号、性别。 3查询 1001课程没有成绩的学生学号、课程号

4查询JSJ 、SX、WL 系的年龄大于25岁的学生学号,姓名,结果按系排列 5按10分制查询学生的sno,cno,10分制成绩

(1-10分 为1 ,11-20分为2 ,30-39分为3,。。。90-100为10) 6查询 student 表中的学生共分布在那几个系中。(distinct) 7查询0001号学生1001,1002课程的成绩。

二 统计

1查询姓名中有“明”字的学生人数。 2计算‘JSJ’系的平均年龄及最大年龄。 3查询学生中姓名为张明、赵英的人数

4计算每一门课的总分、平均分,最高分、最低分,按平均分由高到低排列 5 计算 1001,1002 课程的'平均分。

6 查询平均分大于80分的学生学号及平均分 7 统计选修课程超过 2 门的学生学号

8 统计有10位成绩大于85分以上的课程号。 9 统计平均分不及格的学生学号

10 统计有大于两门课不及格的学生学号

三 连接

1查询 JSJ 系的学生选修的课程号

2查询选修1002 课程的学生的学生姓名 (不用嵌套及嵌套2种方法) 3查询数据库原理不及格的学生学号及成绩

4查询选修“数据库原理”课且成绩 80 以上的学生姓名(不用嵌套及嵌套2种方法) 5查询平均分不及格的学生的学号,姓名,平均分。 6查询女学生平均分高于75分的学生姓名。

7查询男学生学号、姓名、课程号、成绩。(一门课程也没有选修的男学生也要列出,不能

四 嵌套、相关及其他

1 查询平均分不及格的学生人数

2 查询没有选修1002 课程的学生的学生姓名

3 查询平均分最高的学生学号及平均分 (2种方法 TOP , any , all) *4 查询没有选修1001,1002课程的学生姓名。

5 查询1002课程第一名的学生学号(2种方法) 6 查询平均分前三名的学生学号

7 查询 JSJ 系的学生与年龄不大于19岁的学生的差集

8 查询1001号课程大于90分的学生学号、姓名及平均分大于85分的学生学号、姓名 9 查询每门课程成绩都高于该门课程平均分的学生学号 10 查询大于本系科平均年龄的学生姓名

答案

参考答案

1 create table student (sno6), sname var8), ssex2), sagesmallint, sdept var15), primary key(sno));

create table sc

(sno6), cno 4),

grade decimal(12,2), primary key(sno,cno));

into student

values( ’4001’,’赵茵’,’男’,20,’SX’)

from student

student

alter table student add sbirthdate datetime

1 select sno, sname, sage from student

where ssex=’女’ and sage between 19 and 21order by sage desc; 2 select sno, ssexfrom student

where sname like ’_明% ’ ; 3 select sno, cnofrom sc

where grade is null and cno=’1001’ ; 4 select sno, sname from student

where sdept in (’JSJ’,’SX’,’WL’) and sage25 group by sdept;

select sno, cno, grade/10.0+1 as levelfrom sc ;

select distinct sdept from student ; select grade from sc

where sno=’0001’ and (cno=’1001’ or cno=’1002’) ;

select count(*) from student where sname like ’%明% ’ ; select avg(sage),max(sage) from student where sdept=’JSJ’ ; select cno,sum(grade),avg(grade),max(grade),min(grade) from sc group by cno

order by avg(grade) desc ;

select cno, avg(grade) from sc where cno in(‘1001’,’1002’) group by cno ;

select sc.sno ,avg(grade) from scgroup by sc.sno

having avg(grade)80 ;

select sno from sc group by sno having count(*)2 ;

select cno from sc where grade85 group by cno having count(*)=10 ; select sno from sc group by sno having avg(grade)60 ;

select sno from sc where grade60 group="" by="" sno="" having=""2 ;

select cno from student,sc where student.sno=sc.sno and sdept=’JSJ’ ; a:select sname from student,sc where student.sno=sc.sno and cno=’1002’

b:select sname from student where sno in (select sno from sc where cno=’1002’)

select sno,grade from sc,course

where sc.cno=course.cno and cname=’数据库原理’ and grade60 a:select sname from student ,sc,course

where student.sno=sc.sno and sc.cno=course.cno and grade80 and cname=’ 数据库原理’ b:select sname from student where sno in (select sno from sc where grade80 and cno in (select cno from course where cname=’ 数据库原理’)) select sno,sname,avg(grade) from sc,studentwhere student.sno=sc.snogroup by student.sno having avg(grade)60

a:select sname from student where ssex=’女’ and sno in(select sno from sc group by sno having avg(grade)75)

b:select sname from sc,student where student.sno=sc.sno and ssex=’女’group by student.sno having avg(grade)75

select student.sno,sname,cno,grade from student left join sc on student.sno=sc.sno and ssex=’男’

select count(*) from student where sno in( select sno from sc group by sno havingavg(grade)60)

select sname from student where sno not in(select sno from sc where cno=’1002’)

student

0001 aaX 0002 bb

0003 ccX Sc

0001 1001 0001 1002 0002 1001 0003 1002

Select sname from student where not exists(select* from sc where cno=’1002’ and sc.sno=student.sno)

a:select top 1 sno,avg(grade) from sc group by sno order by avg(grade) desc b:select sno, avg(grade) from sc group by sno

having avg(grade)=(select top 1 avg(grade) from scgroup by sno order by avg(grade) desc) c:select sno, avg(grade) from sc group by sno

having avg(grade)=all ( select avg(grade) from sc group by sno)

select sname from student where not exists(

select * from course where cno in(‘1001’,’1002’) and

not exists(select * from sc where sno =student.sno and cno=course.cno) ) a:select top 1 sno from sc cno=’1002’ order by grade desc b:select sno from sc where cno=’1002’ and grade =all (

;

SQL的练习,求答案!!!

有一些类似的题看看吧 一定有帮助

实验一

练习1、请查询表DEPT中所有部门的情况。

select * from dept;

练习2、查询表DEPT中的部门号、部门名称两个字段的所有信息。

select deptno,dname from dept;

练习3、请从表EMP中查询10号部门工作的雇员姓名和工资。

select ename,sal from emp where deptno=10;

练习4、请从表EMP中查找工种是职员CLERK或经理MANAGER的雇员姓名、工资。

select ename,sal from emp where job='CLERK' or job='MANAGER';

练习5、请在EMP表中查找部门号在10-30之间的雇员的姓名、部门号、工资、工作。

select ename,deptno,sal,job from emp where deptno between 10 and 30;

练习6、请从表EMP中查找姓名以J开头所有雇员的姓名、工资、职位。

select ename,sal,job from emp where ename like 'J%';

练习7、请从表EMP中查找工资低于2000的雇员的姓名、工作、工资,并按工资降序排列。

select ename,job,sal from emp where sal=2000 order by sal desc;

练习8、请从表中查询工作是CLERK的所有人的姓名、工资、部门号、部门名称以及部门地址的信息。

select ename,sal,emp.deptno,dname,loc from emp,dept where emp.deptno=dept.deptno and job=’CLERK’;

练习9、查询表EMP中所有的工资大于等于2000的雇员姓名和他的经理的名字。

select a.ename,b.ename from emp a,emp b where a.mgr=b.empno(+) and a.sal=2000;

练习10、在表EMP中查询所有工资高于JONES的所有雇员姓名、工作和工资。

select ename,job,sal from emp where sal(select sal from emp where ename=’JONES’);

练习11、列出没有对应部门表信息的所有雇员的姓名、工作以及部门号。

select ename,job,deptno from emp where deptno not in (select deptno from dept);

练习12、查找工资在1000~3000之间的雇员所在部门的所有人员信息

select * from emp where deptno in (select distinct deptno from emp where sal between 1000 and 3000);

练习13、雇员中谁的工资最高。

select ename from emp where sal=(select max(sal) from emp);

select ename from (select * from emp order by sal desc) where rownum=1;

*练习14、雇员中谁的工资第二高(考虑并列第一的情况,如何处理)。

select ename,sal from (select ename ,sal from emp where sal(select max(sal) from emp) order by sal desc) where rownum=1;

实验二

1. 查询所有雇员的姓名、SAL与COMM之和。

select ename,sal+nvl(comm,0) “sal-and-comm” from emp;

2. 查询所有81年7月1日以前来的员工姓名、工资、所属部门的名字

select ename,sal,dname from emp,dept where emp.deptno=dept.deptno and hiredate=to_date(‘1981-07-01’,’yyyy-mm-dd’);

3. 查询各部门中81年1月1日以后来的员工数

select deptno,count(*) from emp where hiredate=to_date(‘1981-01-01’,’yyyy-mm-dd’) group by deptno;

4. 查询所有在CHICAGO工作的经理MANAGER和销售员SALESMAN的姓名、工资

select ename,sal from emp where (job=’MANAGER’ or job=’SALES’) and deptno in (select deptno from dept where loc=’CHICAGO’);

5. 查询列出来公司就职时间超过24年的员工名单

select ename from emp where hiredate=add_months(sysdate,-288);

6. 查询于81年来公司所有员工的总收入(SAL和COMM)

select sum(sal+nvl(comm,0)) from emp where to_char(hiredate,’yyyy’)=’1981’;

7. 查询显示每个雇员加入公司的准确时间,按××××年××月××日 时分秒显示。

select ename,to_char(hiredate,'yyyy-mm-dd hh24:mi:ss') from emp;

8. 查询公司中按年份月份统计各地的录用职工数量

select to_char(hiredate,'yyyy-mm'),loc,count(*) from emp,dept

where emp.deptno=dept.deptno group by to_char(hiredate,'yyyy-mm'),loc;

9. 查询列出各部门的部门名和部门经理名字

select dname,ename from emp,dept where emp.deptno=dept.deptno and job=’MANAGER’;

10. 查询部门平均工资最高的部门名称和最低的部门名称

select dname from dept where deptno=(select deptno from (select deptno from emp group by deptno order by avg(sal) ) where rownum=1)

union all select dname from dept where deptno=(select deptno from (select deptno from emp group by deptno order by avg(sal) desc ) where rownum=1);

11. *查询与雇员号为7521员工的最接近的在其后进入公司的员工姓名

select ename from (select ename from

(select ename from emp where hiredate(select hiredate from emp where empno=7521) order by hiredate ) where rownum=1)


新闻标题:nosql练习题,nosql第二章课后题
链接分享:http://pwwzsj.com/article/hosgsg.html