SQL语句(回答OK语句运行成功追加20)

来源:百度知道 编辑:UC知道 时间:2024/05/17 15:24:59
book 表
book_id 书号
sort 图书种类
book_name 书名
writer 作者
output 出版社
price 单价

borrow 表
reader_id 借书证号
book_id 书号
borrow_date 借书日期

reader 表
reader_id 借书证号
company 单位
name 姓名
sex 性别
grade 职务
addr 地址

17)* 找出当前至少借阅了2本图书(大于等于2本)的读者姓名及其所在单位。

18) 分别找出借书人次数多于1人次的单位及人次数。

19) 找出藏书中各个出版单位的名称、每个出版社的书籍的总册数(每种可能有多册)、书的价值总额。

20) 查询经济系是否还清所有图书。如果已经还清,显示该系所有读者的姓名、所在单位和职称。

17)select distinct [name],company
from reader,borrow
where reader.reader_id=borrow.reader_id
and (select count(reader_id) from borrow)>=2;

18)select company,count(borrow.reader_id)
from reader,borrow
where reader.reader_id=borrow.reader_id
group by company
having count(company) >1;

19)select output,count(book_id),sum(price)
from book
group by output;

20)select [name],company,grade
from reader
where not exists(select * from reader,borrow
where reader.reader_id=borrow.reader_id and company='经济系');

select name,company from reader where read_id in (select reader_id from borrow
where having count (reader_id )>=2
group by reader_id )