SQL语句基础3:查询操作

接SQL语句基础1,2

1.找出姓李的读者姓名和所在单位

use bookManager
select readerName,readerDepartment
from reader
where readerName like '李%'


2.列出图书库中所有藏书的书名及出版单位

use bookManager
select distinct bookName,bookPublish
from books


3.查找高等教育出版社的 所有图书及单价,结果按单价降序排序

use bookManager
select bookName,bookPrice
from books
where bookPublish='高等教育出版社'
order by bookPrice desc


4.查找价格介于10元和20元之间的图书种类,结果按出版单位和单价升序排序

use bookManager
select bookStyle,bookPublish,bookPrice
from books
where bookPrice between 10 and 20
order by bookPublish,bookPrice


5.查找书名以计算机打头的所有图书和作者

use bookManager
select distinct bookName,bookWritter
from books
where bookName like '计算机%'


6.检索同时借阅了总编号为112266和449901两本书的借书证号

use bookManager
--解法一
select '借书证号:',readerId
from borrow
where bookId=112266 and readerId in(
select readerId
from borrow
where bookId=449901
)
--解法二
select '借书证号',b1.readerId
from borrow b1,borrow b2
where b1.bookId='112266' and b2.bookId='449901' and b1.readerId=b2.readerId


7.查找所有借了书的读者的姓名及所在单位

use bookManager
select distinct readerName,readerDepartment
from reader,borrow
where borrow.readerId=reader.readerId


8.找出李某所借图书的所有图书的书名及借书日期

use bookManager
select readerName,bookName,checkInTime
from borrow,reader,books
where readerName like '李%'
and reader.readerId = borrow.readerId
and borrow.bookId=books.bookId


9.找出借阅了FoxPro大全一书的借书证号

use bookManager
select borrow.readerId,bookName
from books,borrow
where borrow.bookId=books.bookId
and books.bookName='FoxPro大全'


10.找出与赵正义在同一天借书的读者姓名、所在单位及借书日期

use bookManager
select distinct readerName,readerDepartment,checkInTime
from borrow,reader
where reader.readerId=borrow.readerId
and checkInTime in(
select checkInTime
from reader,borrow
where readerName='赵正义'
and reader.readerId=borrow.readerId
)


11.求科学出版社图书的最高单价、最低单价、平均单价

use bookManager
select max(bookPrice) as 最高价,
min(bookPrice) as 最低价,
avg(bookPrice) as 平均价
from books
where bookPublish='科学出版社'


12.求信息系当前借阅图书的读者人次数

use bookManager
select '信息系当前借阅图书人数',count(distinct borrow.readerId)
from reader,borrow
where borrow.readerId=reader.readerId
and readerDepartment='信息系'


13.求出各个出版社图书的最高价格、最低价格和册数

use bookManager
select bookPublish as 出版社,
max(bookPrice) as 最高价,
min(bookPrice) as 最低价,
count(distinct bookId) as 册数
from books
group by bookPublish


14.找出藏书中各个出版单位的册数、价值总额

use bookManager
select bookPublish as 出版社,
COUNT(*) as 册数,
sum(bookPrice) as 价值总额
from books
group by bookPublish
order by COUNT(*),SUM(bookPrice)

你可能感兴趣的:(SQL语句基础3:查询操作)