10-161 向借阅表中插入一条记录
insert into 借阅
(账号,条形码)
values
('D004','TP204.2');
10-162 在读者表中查询全部读者信息,要求女性在前男性在后,同为女性读者的按账号升序排列
select *
from 读者
order by 性别 desc,账号;
10-163 查询读者表中男女读者各自的人数
select 性别,count(*) as 人数
from 读者
group by 性别;
10-164 在读者表中查询余额最高的读者的全部信息
select *
from 读者
order by 余额 desc
limit 1;
10-165 在读者表中查询账户余额的最高值和最低值
select max(余额) as 最高余额,min(余额) as 最低余额
from 读者
10-166 在读者表中查询账号和姓名
select 账号,姓名 from 读者;
10-167 在读者表查询账号D002和D003两位读者的全部信息
select * from 读者 where 账号 in ('D002','D003');
10-168 在读者表中查询余额在500元以下(不包括500元)的女性读者的全部信息
select * from 读者
where 性别='女' and 余额<500;
10-169 查询姓王的读者的账号、姓名和性别,要求使用left函数
select 账号,姓名,性别
from 读者
where left(姓名,1) = '王';
-- where 姓名 like '王%';
10-170 查询读者表中余额介于500到1000(包括500,不包括1000)之间的读者的全部信息
select * from 读者
where 余额 between 500 and 999 ;
10-171 查询图书表中售价最高的图书的全部信息
select * from 图书
order by 售价 desc
limit 0,1;
10-172 查询读者表中有哪些等级,结果中不能出现重复值
select distinct 等级
from 读者;
10-173 在读者表中查询所有等级为“白银”的读者的余额之和
select sum(余额) as 白银读者余额之和
from 读者
where 等级 = '白银';
10-174 通过读者和借阅表,查询读者信息,包括以下字段:账号,姓名,性别,条形码,借书日期和还书日期
select 读者.账号,姓名,性别,条形码,借书日期,还书日期
from 读者,借阅
where 读者.账号=借阅.账号;
10-175 B2-1查找订单数最多的员工信息
select LastName,FirstName,Title
from employees,
(
select EmployeeID,count(OrderID) as num
from orders
group by EmployeeID
order by num desc
limit 1
) as b
where employees.EmployeeID = b.EmployeeID;
10-176 向订单表中插入一条新记录
insert into 订单
values
(10331,'J101','023',null,null);
10-177 向顾客表中插入一条新记录
insert into 顾客
values
('Z001','大胜教育',null,'淄博',null);
10-178 将订单表中2015年以前的订单数据删除
delete from 订单
where year(订单日期)<=2015;
10-179 将顾客表中顾客编号最后两位是“10”和“11”的记录删除
delete from 顾客
where 顾客编号 like '%10' or 顾客编号 like '%11';
10-180 将编号为“10330”的订单的运费下调10%
update 订单
set 运费 = 运费 * 0.9
where 订单编号 = 10330;