关于sql语句的基础问题

来源:百度知道 编辑:UC知道 时间:2024/06/09 20:23:08
create table book(
bno char(8) not null, 书号
category char(10) not null, 类别
title varchar(40) not null, 出版社
year int , 年份
author char(20), 作者
price decimal(7,2) ,价格
total int not null, 目前 未接触的册书
primary key (bno)

);

create table card(
cno char(7) not null, 借书证号
name char(10) not null, 姓名
department varchar(40) not null, 系
primary key (cno)
)

create table borrow(
cno char(7) not null,
bno char(8) not null,
return_date date,
primary key(cno,bno),
foreign key(cno) references card(cno),
foreign key(bno) references card(bno),

)

1、目前已借出多少册书
2、年份最久远的书
3、哪一年的图书最多
4、平均每本借书证借书册书
5、本年2007未借过书的借书证
6、哪个系的同学平均借书最多
7、最近两年2006.2007都未被借出过的书

大家帮帮我~~~~~

1.
select count(bno) from borrow;
2.
select * from book
where year=min(year);
3.
select year,count(bno) "Number" form book
group by year
order by Number desc;
4.
select count(bno)/count(cno)
from borrow;
5.
select cno,name from card
where cno in (select cno from borrow where return_date < to_date(yyyy,2007)
or cno not in (select cno from borrow);
余下的回来补上