use librarydb;
select 书名,出版社 from 图书表;
select 书名,单价,case when 单价>=40 then '很贵' when 单价>=30 and 单价<40 then '有点贵' when 单价>=20 and 单价<30 then '适中' else '实惠' end as '单价等级' from 图书表;
select 书名,round(单价)*数量 as 订购金额 from 图书表;
select distinct 类别 from 图书表;
select * from 图书表 where 单价>30;
select * from 图书表 where 类别='计算机' and 单价>30;
【实训5----单表查询】*******************************************************************************
select distinct 书号,库存状态 from 库存表;
select 姓名 as name ,单位 as college from 读者表;
select 书名,数量*单价 as 金额 from 图书表;
select 条码,库存状态,case when 库存状态='在馆' then '1'when 库存状态='借出' then '0'when 库存状态='丢失' then '-1'end as 库存状态1 from 库存表;
【实训5----条件查询】*******************************************************************************
select 书名,数量,出版社 from 图书表 where 数量>=10;
select * from 库存表 where 库存状态='借出' and 位置 like '%A%';
select * from 图书表 where (类别='财经' or 类别='文学') and 数量>5;
select * from 借阅表 where 还书日期 is null;
【实训5----多表查询】*******************************************************************************
select 姓名,类名,单位 from 读者表,读者类型表 where 读者表.类别号=读者类型表.类别号;
select 读者表.读者编号,姓名,借阅日期,借阅状态 from 读者表,借阅表 where 读者表.读者编号=借阅表.读者编号;
select * from 读者表,借阅表 where 读者表.读者编号=借阅表.读者编号 and 姓名='张小东';
select 书号,借阅表.条码 from 库存表,借阅表 where 库存表.条码=借阅表.条码 and 借阅状态='借阅';
select 姓名,单位,可借天数,可借数量 from 读者表,读者类型表 where 读者表.类别号=读者类型表.类别号;
select 姓名,书名,借阅日期,借阅状态 from 借阅表,读者表,图书表,库存表 where 库存表.书号=图书表.书号 and 借阅表.读者编号=读者表.读者编号 and 库存表.条码=借阅表.条码;
select 库存表.条码,位置,读者编号 from 库存表 left join 借阅表 on 库存表.条码=借阅表.条码;
use bookstore;
select sell.*,members.姓名 from sell,members where sell.用户号=members.用户号 and members.姓名='张三';
select * from sell where 用户号 in(select 用户号 from members where 姓名='张三');