数据库第三章练习1
数据库第三章所有例题参考答案

11级信管,保密,图档上机考试题目与参考答案3.3Simple Select Statements1.EXAMPLE 3.3.1find the aid values and names of agents that are based in New York. select aid, aname from agents where city=’New York’;2.EXAMPLE3.3.3Retrieve all pid values of parts for which orders are placed.select distinct pid from orders;3.EXAMPLE 3.3.4retrieve all customer-agent name pairs, (cname, aname), where the customer places an order through the agent.select distinct ame,agents.anamefrom customers,orders,agentswhere customers.cid=orders.cid and orders.aid=agents.aid;4.EXAMPLE 3.3.6all pairs of customers based in the same city.select c1.cid, c2.cidfrom customers c1, customers c2where c1.city = c2.city and c1.cid < c2.cid;5.EXAMPLE 3.3.7find pid values of products that have been ordered by at least twocustomers.select distinct x1.pidfrom orders x1, orders x2where x1.pid = x2.pid and x1.cid < x2.cid;6.EXAMPLE 3.3.8Get cid values of customers who order a product for which an order is also placed by agent a06.select distinct y.cidfrom orders x, orders ywhere y.pid = x,pid and x.aid = ‘a06’;3.4Subqueries7.EXAMPLE 3.4.1Get cid values of customers who place orders with agents in Duluth or Dallas.select distinct cid from orderswhere aid in (select aid from agentswhere city= ‘Duluth’ or city = ‘Dallas’)8.EXAMPLE 3.4.2to retrieve all information concerning agents based in Duluth or Dallas (very close to the Subquery in the previous example).select * from agentswhere city in (‘Duluth’, ‘Dallas’ );or select *from agentswhere city = ‘Duluth’ or city = ‘Dallas’;9.EXAMPLE 3.4.3to determine the names and discounts of all customers who place orders through agents in Duluth or Dallas.select distinct cname, discnt from customerswhere cid in (select cid from orders where aid in(select aid from agents where city in (‘Duluth’, ‘Dallas’ ))); 10.EXAMPLE 3.4.4to find the names of customers who order product p05.select distinct cname from customers, orderswhere customers.cid = orders.cid and orders.pid = ‘p05’or select disti nct cname from customers where ‘p05’ in(select pid from orders where cid = customers.cid);11.EXAMPLE 3.4.5Get the names of customers who order product p07 from agent a03. select distinct cname from customerswhere cid in (select cid from orders where pid = ‘p07’ and aid = ‘a03’) 12.EXAMPLE 3.4.6to retrieve ordno values for all orders placed by customers in Duluth through agents in New York.select ordno from orders x where exists(select * from customers c, agents awhere c.cid = x.cid and a.aid = x.aid and c.city = ‘Duluth’ anda.city=‘New York’);13.EXAMPLE 3.4.7find aid values of agents with a minimum percent commission.select aid from agents where percent = (select min(percent) from agents);14.EXAMPLE 3.4.8find all customers who have the same discount as that of any of the customers in Dallas or Boston.select cid, cname from customerswhere discnt = some (select discnt from customerswhere city = ‘Dallas’ or city = ‘Boston’);15.EXAMPLE 3.4.9Get cid values of customers with discnt smaller than those of any customers who live in Duluth.select cid from customerswhere discnt <all (select discnt from customerswhere city = ‘Duluth’);16.EXAMPLE 3.4.10Retrieve all customer names where the customer places an order through agent a05.select distinct ame from customers cwhere exists (select * from orders xwhere c.cid = x.cid and x.aid = ‘a05’);or select distinct ame from customers c, orders xwhere c.cid = x.cid and x.ai d = ‘a05’ ;17.EXAMPLE 3.4.11Get cid values of customers who order both products p01 and p07. select distinct cid from orders xwhere pid = ‘p01’ and exsits (select * from orderswhere cid = x.cid and pid = ‘p07’);orselect distinct x.cid from orders x, orders ywhere x.pid = ‘p01’ and x.cid = y.cid and y.pid = ‘p07’;18.EXAMPLE 3.4.12Retrieve all customer names where the customer does not place an order through agent a05.select distinct ame from customers cwhere not exists (select * from orders xwhere c.cid = x.cid and x.aid = ‘a05’);19.EXAMPLE 3.4.13retrieving all customer names where the customer does not place an order through agent a05, but using the two equivalent NOT IN and <>ALLpredicates in place of NOT EXISTS.select distinct ame from customers cwhere c.cid not in (select cid from orders where aid = ‘a05’);or select ame from customers cwhere c.cid <>all (select cid from orders where aid = ‘a05’);20.EXAMPLE 3.4.14Find cid values of customers who do not place any order through agent a03.select distinct cid from orders xwhere not exists (select * from orderswhere cid = x.cid and aid = ‘a03’);orselect cid from customers cwhere not exists (select * from orderswhere cid = c.cid and aid = ‘a03’);21.EXAMPLE 3.4.15Retrieve the city names containing customers who order product p01. select distinct city from customers where cid in(select cid from orders where pid = ‘p01’);or select distinct city from customers where cid =some(select cid from orders where pid = ‘p01’);or select distinct city from customers c where exsits(select * from orders where cid = c.cid and pid = ‘p01’);or select distinct city from customers c, orders xwhere x.cid = c.cid and x.pid = ‘p01’;or select distinct city from customers c where ‘p01’ in(select pid from orders where cid = c.cid);3.5UNION Operators and FOR ALL Conditions 22.EXAMPLE 3.5.1to create a list of cities where either a customer or an agent, or both, is based.select city from customersunion select city from agents;23.EXAMPLE 3.5.2Get the cid values of customers who place orders with all agents based in New York.select c.cid from customers cwhere not exsits(select * from agents awhere a.city = ‘New York’ and not exsits(select * from orders xwhere x.cid = c.cid and x.aid = a.aid));24.EXAMPLE 3.5.3Get the aid values of agents in New York or Duluth who place orders forall products costing more than a dollar.select aid from agents awhere (a.city = ‘New York’ or a.city = ‘Duluth’)and not exsits(select p.pid from products pwhere p.price > 1.00 and not exsits(select * from orders xwhere x.pid = p.pid and x.aid = a.aid));25.EXAMPLE 3.5.4Find aid values of agents who place orders for product p01 as well as for all products costing more than a dollar.select a.aid from agents a where a.aid in(select aid from orders where pid = ‘p01’)and not exsits (select p.pid from products pwhere p.price > 1.00 and not exsits (select * from orders xwhere x.pid = p.pid and x.aid = a.aid));or select distinct y.aid from orders ywhere y.pid = ‘p01’ and not exsits(select p.pid from products pwhere p.price > 1.00 and not exsits(select * from orders xwhere x.pid = p.pid and x.aid = y.aid));26.EXAMPLE 3.5.6Find pid values of products supplied to all customers in Duluth.select pid from products pwhere not exsits(select c.cid from customers cwhere c.city = ‘Duluth’and not exists(select * from orders xwhere x.pid = p.pid and x.cid = c.cid));3.7 Set Functions in SQL27.EXAMPLE 3.7.1determine the total dollar amount of all orders.select sum(dollars) as totaldollars from orders28.EXAMPLE 3.7.2To determine the total quantity of product p03 that has been ordered. select sum(qty) as TOTAL from orders where pid=’p03’29.EXAMPLE 3.7.4Get the number of cities where customers are based.select count(distinct city) from customers30.EXAMPLE 3.7.5List the cid values of alt customers who have a discount less than the maximum discount.select cid from customerswhere discnt < (select max(discnt) from customers)31.EXAMPLE 3.7.6Find products ordered by at least two customers.select p.pid from products pwhere 2 <=(select count(distinct cid) from orders where pid=p.pid)图档的学生的上机考查的考题到此为止___________________________________________________________ ___________________________________________________________ 信管,保密的学生上机考查还包括下面的题目32.EXAMPLE 3.7.7Add a row with specified values for columns cid, cname, and city (c007, Windix, Dallas, null)to the customers table.insert into customers(cid, cname, city)values (‘c007’, ‘Windix’, ‘Dallas’)33.EXAMPLE 3.7.9After inserting the row (c007, Windix, Dallas, null) to the customers table in Example 3.7.7, assume that we wish to find the average discount of all customers.select avg(discnt) from customers3.8 Groups of Rows in SQL34.EXAMPLE 3.8.1to calculate the total product quantity ordered of each individual product by each individual agent.select pid, aid, sum(qty) as TOTAL from ordersgroup by pid, aid35.EXAMPLE 3.8.2Print out the agent name and agent identification number, and the product name and product identification number, together with the total quantity each agent supplies of that product to customers c002 and c003.select aname, a.aid, pname, p.pid, sum(qty)from orders x, products p, agents awhere x.pid = p.pid and x.aid = a.aid and x.cid in (‘c002’, ‘c003’)group by a.aid, a.aname, p.pid, p.pname36.EXAMPLE 3.8.3Print out all product and agent IDs and the total quantity ordered of the product by the agent, when this quantity exceeds 1000.select pid, aid, sum(qty) as TOTAL from ordersgroup by pid, aidhaving sum(qty) > 100037.EXAMPLE 3.8.4Provide pid values of all products purchased by at least two customers. select distinct pid from ordersgroup by pidhaving count(distinct cid) >= 23.9 A Complete Description of SQL Select38.EXAMPLE 3.9.1List all customers, agents, and the dollar sales for pairs of customers and agents, and order the result from largest to smallest sales totals. Retain only those pairs for which the dollar amount is at least equal to 900.00. select ame, c.cid, a.aname, a.aid, sum(dollars) as casalesfrom customers c, orders o, agents awhere c.cid = o.cid, and a.aid = o.aidgroup by ame, c.cid, a.aname, a.aidhaving sum(o.dollars) >= 900.00order by casales desc39.EXAMPLE 3.9.2listed the cid values of all customers with a discount less than the maximum discount.select cid from customerswhere discnt < (select max(discnt) from customers)40.EXAMPLE 3.9.3Retrieve the maximum discount of all customers.select max(discnt) from customers;select distinct discnt from customers cwhere discnt >= all (select discnt from customers dwhere d.cid<>c.cid)41.EXAMPLE 3.9.4Retrieve all data about customers whose cname begins with the letter “A”.select * from customers where cname like ‘A%’42.EXAMPLE 3.9.5Retrieve cid values of customers whose cname does not have a third letter equal to “%”.select cid from customers where cname not like ‘__[%]’43.EXAMPLE 3.9.6Retrieve cid values of customers whose cname begins “Tip_” and has an arbitrary number of characters following.select cid from customers where cname like ‘TIP\[_]%’44.EXAMPLE 3.9.7Retrieve cid values of customers whose cname starts with the sequence “ab\”.select cid from customers where cname like ‘ab\%’3.10 Insert, Update, and Delete Statements 45.EXAMPLE 3.10.1Add a row with specified values to the orders table, setting the qty and dollars columns null.insert into orders (ordno, month, cid, aid, pid)values (1107, ‘aug’, ‘c006’, ‘a04’, ‘p01’)46.EXAMPLE 3.10.2Create a new table called swcusts of Southwestern customers, and insert into it all customers from Dallas and Austin.create table swcusts (cid char(4) not null,cname varchar(13),city varchar(20),discnt real);insert into swcustsselect * from customerswhere city in (‘Dallas’, ‘Austin’)47.EXAMPLE 3.10.3Give all agents in New York a 10% raise in the percent commission they earn on an order.update agents set percent = 1.1 * percent where city = ‘New York’48.EXAMPLE 3.10.4Give all customers who have total orders of more than $1000 a 10% increase in the discnt.update agents set percent = 1.1 * discntwhere cid in(select cid from orders group by cid having sum(dollars) > 1000) 49.EXAMPLE 3.10.6Delete all agents in New York.delete from agents where city = ‘New York’50.EXAMPLE 3.10.7Delete all agents who have total orders of less than $600.Delete from agents where aid in(select aid from ordersGroup by aidHaving sum(dollars)<600)51.EXAMPLE 3.11.2Retrieve the names of customers who order products costing $0.50. delete from agents where aid in(select aid from orders group by aid having sum(dollars)<600)(完)。
数据库第三章习题参考

5.求至少用了供应商S1所供应的全部零件的工程号JNO。 即查找:不存在这样的零件y,供应商S1供应了y,而工程x为选用y。 Select distinct jno From spj z Where not exists (select * from spj x where sno=‘S1’ and not exists (select * from spj y where y.pno=x.pno and y.jno=z.jno));
习题三 第5题
1. 找出所有供应商的姓名及其所在城市。 Select sname, city from s; 2. 找出所有零件的名称、颜色、重量。 Select pname, color, weight from p; 3.找出使用供应商S1所供应零件的工程项目代码。 Select jno from spj where sno=‘S1’;
7. 找出没有使用天津产的零件的工程项目代码。 Select jno from j where not exists (Select * from spj where spj.jno=j.jno and sno in (Select sno from s where city=‘天津’) );
3.求供应工程J1零件为红色的供应商号码。 Select sno from spj, p Where spj.pno=p.pno and jno=‘J1’ and color=‘红’; 或: Select sno from spj Where jno =‘J1’ and pno in (Select pno from p Biblioteka where color=‘红’ );
6. 找出使用上海产的零件的工程项目名。 Select jname from j,spj,s where j.jno=spj.jno and spj.sno=s.sno and s.city=‘上海’; 或: Select jname from j where jno in (Select jno from spj, s where spj.sno=s.sno and s.city=‘上海’);
数据库第3章习题参考答案

第3章习题解答1.选择题(1)表设计器的“允许空”单元格用于设置该字段是否可输入空值,实际上就是创建该字段的(D)约束。
A.主键B.外键C.NULL D.CHECK(2)下列关于表的叙述正确的是(C)。
A.只要用户表没有人使用,则可将其删除B.用户表可以隐藏C.系统表可以隐藏D.系统表可以删除(3)下列关于主关键字叙述正确的是( A )。
A.一个表可以没有主关键字B.只能将一个字段定义为主关键字C.如果一个表只有一个记录,则主关键字字段可以为空值D.都正确(4)下列关于关联叙述正确的是( C )。
A.可在两个表的不同数据类型的字段间创建关联B.可在两个表的不同数据类型的同名字段间创建关联C.可在两个表的相同数据类型的不同名称的字段间创建关联D.在创建关联时选择了级联更新相关的字段,则外键表中的字段值变化时,可自动修改主键表中的关联字段(5)CREATE TABLE语句(C )。
A.必须在数据表名称中指定表所属的数据库B.必须指明数据表的所有者C.指定的所有者和表名称组合起来在数据库中必须唯一D.省略数据表名称时,则自动创建一个本地临时表(6)删除表的语句是(A)。
A.Drop B.Alter C.Update D.Delete (7)数据完整性不包括(B )。
A.实体完整性B.列完整性C.域完整性D.用户自定义完整(8)下面关于Insert语句的说法正确的是(A )。
A.Insert一次只能插入一行的元组B.Insert只能插入不能修改C.Insert可以指定要插入到哪行D.Insert可以加Where条件(9)表数据的删除语句是( A )。
A.Delete B.Inser C.Update D.Alter (10)SQL数据定义语言中,表示外键约束的关键字是(B )。
A.Check B.Foreign Key C.Primary Key D.Unique2.填空题(1)数据通常存储在表中,表存储在数据库文件中,任何有相应权限的用户都可以对之进行操作。
数据库基本操作习题与答案

第三章数据库基本操作一、选择题1. 如果需要给当前表增加一个字段,应使用的命令是________。
A) APPEND B) INSERTC) EDIT D) MODIFY STRU2. 设表文件及其索引已打开,为了确保指针定位在物理记录号为1的记录上,应该使用命令________。
A) SKIP 1 B) SKIP -1C) GO 1 D) GO TOP3. 要显示数据库中当前一条记录的内容,可使用命令________。
A) LIST B) BROWSEC) TYPE D) DISPLAY4. 在当前表中,查找第2个女同学的记录,应使用命令________。
A) LOCATE FOR 性别="女"B) LOCATE FOR 性别="女" NEXT 2C) LIST FOR 性别="女"CONTINUED) LOCATE FOR 性别="女"CONTINUE5. Visual FoxPro的数据库表之间可建立两种联系,它们是________。
A) 永久联系和临时联系B) 长期联系和短期联系C) 永久联系和短期联系D) 长期联系和临时联系6. 数据库表的索引中,字段值不能有重复的索引有________种。
A) 1 B) 2C) 3 D) 47. 建立表间临时关联的命令是________。
A) LET RELATION TO命令B) JOIN命令C) SET RELATION TO命令D) 以上都不是8. 通过关键字建立表间的临时关联的前提是________。
A) 父表必须索引并打开B) 子表必须索引并打开C) 两表必须索引并打开D) 两表都不必索引9. 查询设计器的“筛选”选项卡上,“插入”按钮的作用是________。
A) 用于增加查询输出字段B) 用于增加查询的表C) 用于增加查询去向D) 用于插入查询输出条件10. 在多工作区的操作中,如果选择了4,7,8号工作区并打开了相应的数据库,在命令窗口执行命令SELECT 0,其功能是________。
数据库 第三章习题参考答案

三、设计题1.(1)SELECT BAuth FROM Book, PublishWHERE Book.PNo= Publish.PNo AND BName=’操作系统’ AND PName=’高等教育出版社’(2)查找为作者“张欣”出版全部“小说”类图书的出版社的电话。
SELECT PTel FROM Book, PublishWHERE Book.PNo= Publish.PNo AND BType =’小说’ AND BAuth=’张欣’(3)查询“电子工业出版社”出版的“计算机”类图书的价格,同时输出出版社名称及图书类别。
SELECT BPrice, PName, BType FROM Book, PublishWHERE Book.PNo= Publish.PNo AND PName =’电子工业出版社’ AND BType =’计算机’(4)查找比“人民邮电出版社”出版的“高等数学”价格低的同名书的有关信息。
SELECT * FROM BookWHERE BName =’高等数学’AND BPrice<ANY(SELECT BPrice FROM Book,PublishWHERE Book.PNo= Publish.PNo AND PName =’人民邮电出版社’ AND BName =’高等数学’)AND PName <>’人民邮电出版社’(5)查找书名中有“计算机”一词的图书的书名及作者。
SELECT BName, BAuth FROM BookWHERE BName LIKE’%计算机%’(6)在“图书”表中增加“出版时间”(BDate)项,其数据类型为日期型。
ALTER TABLE BookADD BDate datetime(7)在“图书”表中以“作者”建立一个索引。
CREATE INDEX Name ON Book(BAuth) desc2.(1)建立存书表和销售表。
【精选】数据库第三章课后习题

• 14、 • (1)GRANT SELECT ON 职工,部门TO 王明 • (2) GRANT INSERT,DELETE ON 职工,部门TO
李勇
• (3) GRANT SELECT ON 职工WHEN USER() = NAME TO ALL
• (4) GRANT SELECT,UPDATE(工资) ON 职工 TO 刘星
• 7、视图的优点 • 视图能够简化用户的操作 • 视图使用户能以多种角度看待同一数据 • 视图对重构数据库提供了一定程度的逻辑
独立性; • 视图能够对机密数据提供安全保护。
• 8、所有的视图是否都可以更新?
• 不是。视图是不实际存储数据的虚表,因 此对视图的更新,最终要转换为对基本表 的更新。因为有些视图的更新不能惟一有 意义地转换成对相应基本表的更新,所以 ,并不是所有的视图都是可更新的。
SPJ TO 李天明;
• 13、 • (1)INSERT INTO SC(Sno,Cno,Grade)
VALUES("2000012", "1128", NULL); • (2)SELECT Sno,Cno
FROM SC
WHERE Grade IS NULL;
• (3)SELECT cname,grade FROM course,Sc WHERE o=o AND cname="英语"
• (1) SELECT DIST PNO,QTY FROM SPQ
• (2) SELECT DIST * FROM SPQ WHERE SNO="S1‘
• 12、 • (1)GRANT INSERT
ON TABLE S TO 张勇
2020年计算机二级《MySQL》数据库章节练习题及答案

2020年计算机二级《MySQL》数据库章节练习题及答案第三章数据库和表1[单选题]在MySQL中,通常使用________语句来指定一个已有数据库作为当前工作数据库。
INGEDESE参考答案:D2[简答题]请使用MySQL命令行客户端在MySQL中创建一个名为db_test的数据库。
参考解析:在MySQL命令行客户端输入如下SQL语句即可实现:mysql>CREATE DATABASE db_test;Query OK,1 row affected(0.05 see)3[简答题]列名name修改为username参考解析:alter table user change column name username varchar(20);4[单选题]设置表的默认字符集关键字是( )A.DEFAULT CHARACTERB.DEFAULT SETC.DEFAULTD.DEFAULT CHARACTER SET参考答案:D5[填空题]在创建数据库时,能够使用( )子句确保如果数据库不存有就创建它,如果存有就直接使用它。
参考解析:IF NOT EXISTS6[简答题]创建数据库sxcj,引擎采用InnoDB,在sxcj中创建表xs包含字段如下字段名称数据类型说明snoint主键snameChar(8)名字ZhuanyemingChar(10)专业名sexChar(1)性别sbirdate生日photoblob照片commenttext注释参考解析:create database sxcj;use sxcjcreate table xs( sno int not null auto_increment primary key ,sname char(8) not null,zhuanyeming char(10) null,sex char(1) not null,sbir date not null,photo blob null,comment text null)engine=InooDB;7[填空题] 在CREATE TABLE语句中,通常使用________关键字来指定主键。
1数据库原理习题与答案_第3章数据库系统结构(范文)

1数据库原理习题与答案_第3章数据库系统结构(范文)第一篇:1数据库原理习题与答案_第3章数据库系统结构(范文)简答题1.试述数据库系统三级模式结构,这种结构的优点是什么。
答:数据库系统的三级模式结构由外模式、模式和内模式组成。
外模式,亦称子模式或用户模式,是数据库用户能够看见和使用的局部数据的逻辑结构和特征的描述,是数据库用户的数据视图,是与某一应用有关的数据的逻辑表示。
模式,亦称逻辑模式,是数据库中全体数据的逻辑结构和特征的描述,是所有用户的公共数据视图。
模式描述的是数据的全局逻辑结构,外模式涉及的是数据的局部逻辑结构,通常是模式的子集。
内模式,亦称存储模式,是数据在数据库系统内部的表示,即对数据的物理结构和存储方式的描述。
数据库系统的三级模式是对数据的三个抽象级别,它把数据的具体组织留给DBMS管理,使用户能逻辑抽象地处理数据,而不必关心数据在计算机中的表示和存储。
为了能够在内部实现这三个抽象层次的联系和转换,数据库系统在这三级模式之间提供了两层映像:外模式/模式映像和模式/内模式映像,正是这两层映像保证了数据库系统中的数据能够具有较高的逻辑独立性和物理独立性。
2.定义并解释以下术语:模式、外模式、内模式、DDL、DML。
答:模式,亦称逻辑模式,是数据库中全体数据的逻辑结构和特征的描述,是所有用户的公共数据视图。
外模式,亦称子模式或用户模式,是数据库用户能够看见和使用的局部数据的逻辑结构和特征的描述,是数据库用户的数据视图,是与某一应用有关的数据的逻辑表示。
内模式,亦称存储模式,是数据在数据库系统内部的表示,即对数据的物理结构和存储方式的描述。
DDL:数据定义语言,用来定义数据库模式、外模式、内模式的语言。
DML:数据操纵语言,用来对数据库中的数据进行查询、插入、删除和修改的语句。
3.什么叫数据与程序的物理独立性?什么叫数据与程序的逻辑独立性?为什么数据库系统具有数据与程序的独立性?答:数据与程序的逻辑独立性:当模式改变时,由数据库管理员对各个外模式//模式的映像做相应改变,可以使外模式保持不变。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Techer(教师编号,姓名,性别,工作时间,政治面貌,学历,职称,系别,电话号码) Student(学生编号, 姓名, 性别, 年龄,入校日期,政治面貌,籍贯)
Course(课程编号,课程名称,课程类别,学分,任课教师)
SC(学生编号,课程编号,成绩)
1、查询年龄为18岁的所有学生的编号,名称,按照编号升序排序、
2、查询学生的选课成绩合格的学生编号、课程编号、课程成绩、并把成绩转换算为极点(60分对应极点为1,每增加1分,极点增加0.1)
3、查询编号为95016,95017的任课老师教授的课程名称。
4、查询所有课程名称中含有“数据”的课程名称。
5、查询所有选课记录的课程号(不重复显示)。
6、查询所有老师的工龄。
7、统计所有学生的平均年龄。
8、查询每个学生的平均成绩,显示学生编号,平均成绩字段,按照平均成绩降序排列。
9、统计各个课程的选课人数和平均成绩。
10、统计各个课程的选课人数和平均成绩。
11、按照学生编号统计其平均成绩,显示平均成绩在80分以上的学生编号和
平均成绩字段。
1、查询年龄为18岁的所有学生的名称,按照编号升序排序、
select*
from Student
where年龄=18
order by学生编号
2、查询学生的选课成绩合格的学生编号、课程编号、课程成绩、并把成绩转换算为极点(60分对应极点为1,每增加1分,极点增加0.1)
select学生编号,课程编号,成绩,(成绩-60)*0.1+1 as积点
from SC
where成绩>=60
3、查询编号为95016,95017的任课老师教授的课程名称。
select课程名称
from Course
where任课教师in('95016','95017');
或者
select课程名称
from Course
where任课教师='95016'or任课教师='95017';
4、查询所有课程名称中含有“数据”的课程名称。
select课程名称
from Course
where课程名称like'%数据%';
5、查询所有选课记录的课程号(不重复显示)。
select distinct课程编号
from SC
6、查询所有老师的工龄。
select 2011-Year(工作时间)as平均工龄
from Teacher
7、统计所有学生的平均年龄。
select Avg(年龄)as平均工龄
from Student
8、查询每个学生的平均成绩,显示学生编号,平均成绩字段,按照平均成绩降序排列。
select学生编号,Avg(成绩)as平均成绩
from SC
group by学生编号
order by平均成绩desc
9、统计各个课程的选课人数和平均成绩。
select课程编号,count(学生编号)as人数,Avg(成绩)as平均成绩
from SC
group by课程编号
order by平均成绩desc
10、按照职称统计教师的人数。
select职称,count(教师编号)as人数
from Teacher
group by职称
12、按照学生编号统计其平均成绩,显示平均成绩在80分以上的学生编号和平均成绩字段。
select学生编号,Avg(成绩)as平均成绩
from SC
group by学生编号
having Avg(成绩)>=80。