pta mysql训练题集(141-160)

10-141 B1-8查询特定订单的详细信息

select a.CustomerID,CompanyName,a.OrderID,ProductID
from orders as a, customers as b ,orderdetails as c
where a.OrderID=c.OrderID and a.CustomerID=b.CustomerID and City=Madrid;

10-142 查询图书表中售价介于50元到70元之间的图书的全部信息

select * from 图书
where 售价 between 50 and 70;

10-143 查询图书表中条形码左边开始三个字符是“TP3”的图书的全部信息

要求:不能用like运算符构成条件表达式。

select *
from 图书
where 条形码 regexp ^TP3 ;
-- where 条形码 like TP3%;

10-145 查询图书表中书名为“C语言程序设计”和“VB程序设计”的两本书的全部信息 之一

select *
from 图书
where 书名 =C语言程序设计 or 书名 = VB程序设计;

10-146 查询图书表中的图书的条形码和书名,要求结果按条形码升序排序

select 条形码,书名
from 图书
order by 条形码;

10-147 查询图书表中各出版社图书的数目,结果按图书数目降序排序

select 出版社,count(*) as 图书数目
from 图书
group by 出版社
order by 图书数目 desc;

10-148 查询图书表中全部图书的最高售价

select max(售价) as 最高售价 from 图书;

10-149 查询图书表中全部图书的最低售价

select min(售价) as 最低售价 from 图书;

10-150 查询图书表中全部图书的平均售价

select avg(售价) as 平均售价 from 图书;

10-151 查询图书表中全部图书的最高售价、最低售价和平均售价

select max(售价) as 最高售价,min(售价) as 最低售价,avg(售价) as 平均售价
from 图书;

10-152 查询图书表中2018年出版的图书的数目

select count(*) as 2018年出版的图书数目
from 图书
where year(出版日期)=2018;

10-153 查询图书的条形码,书名,出版社和出版日期,要求结果按出版社升序排列,出版社相同的数据按出版日期降序排列

select 条形码,书名,出版社,出版日期
from 图书
order by 出版社,出版日期 desc;

10-154 查询图书表中有哪些出版社,要求结果没有重复值

select distinct 出版社 from 图书;

10-155 通过图书表和借阅表,查询图书的借阅情况,要求结果中包括以下几列:账号,条形码,书名和借书日期

select 账号,book.条形码,书名,借书日期
from 图书 as book,借阅 as borrow
where book.条形码 = borrow.条形码;
insert into 图书
values
(TP211.3,狼图腾,姜戎,null,null,44.5);

10-157 已有一个名为“读者”的表,使用INSERT命令向其中插入一条记录

INSERT into 读者
values
(D005,张兴,男,青铜,null,null);

10-158 将图书表中科学出版社出版的图书价格上涨5%

update 图书 set 售价 = 售价 * 1.05
where 出版社 = 科学出版社;

10-159 将图书表中条形码为TP204.2的图书信息删除

delete from 图书 where 条形码 = TP204.2;

10-160 通过三个表,查询读者借阅图书的信息

select b.账号,姓名,a.条形码,书名,借书日期,还书日期
from 图书 as a,借阅 as b,读者 as c
where a.条形码=b.条形码 and b.账号=c.账号;
经验分享 程序员 微信小程序 职场和发展