SELECT name,addr FROM reader WHERE name LIKE '李%';
SELECT DISTINCT(book_name),output FROM book;
SELECT DISTINCT(book_name),price FROM book
SELECT sort,price FROM book
SELECT DISTINCT(book_name),writer FROM book
SELECT borrow.reader_id FROM borrow ,
SELECT name,company FROM reader
SELECT writer,book_name,
(SELECT borrow_date FROM borrow WHERE book_id in
(SELECT book_id from book WHERE writer LIKE '李%'))
FROM book WHERE writer LIKE '李%';
SELECT reader_id,name,company FROM reader
(SELECT distinct reader_id FROM borrow
WHERE borrow_date >= to_date('2006-10-01','yyyy-mm-dd')) ;
SELECT reader_id FROM borrow WHERE book_id in
(SELECT DISTINCT book_id FROM book
SELECT name,company,
(SELECT reader_id FROM reader WHERE name='赵正义') )
FROM reader WHERE reader_id = (
(SELECT borrow_date FROM borrow WHERE reader_id =
(SELECT reader_id FROM reader WHERE name='赵正义') )
SELECT reader.name, reader.company, borrow.borrow_date
WHERE reader.reader_id = borrow.reader_id
SELECT borrow_date FROM borrow WHERE reader_id =
) AND reader.name <> '赵正义';
日期的关系:昨天 > 今天 > 明天
SELECT reader_id,name,company FROM reader
WHERE borrow_date>=to_date('2006-08-01','yyyy-mm-dd'));
SELECT max(price),min(price),avg(price) FROM book
WHERE output='科学出版社'
14)* 求”信息系”当前借阅图书的读者人次数。
SELECT count(distinct reader_id) FROM borrow
(SELECT reader_id FROM reader WHERE company='信息系');
15) 求出各个出版社图书的最高价格、最低价格和总册数。
SELECT max(price),min(price),count(book_id)
16) 分别找出各单位当前借阅图书的读者人数及所在单位。
SELECT count(reader_id),company FROM reader
WHERE reader_id in (SELECT distinct reader_id FROM borrow)
GROUP BY company;
17)* 找出当前至少借阅了2本图书(大于等于2本)的读者姓名及其所在单位。
SELECT name,company FROM reader WHERE reader_id in
GROUP BY reader_id having count(book_id)>=2)
;
SELECT company,count(reader_id) FROM reader
WHERE reader_id in(SELECT distinct reader_id FROM borrow)GROUP BY company having count(reader_id)>1;
SELECT output,count(book_id),sum(price)
SELECT name,company,grade FROM reader
创建BOOK:(图书表)
CREATE TABLE BOOK (
BOOK_ID NUMBER(10),
SORT VARCHAR2(10),
BOOK_NAME VARCHAR2(50),
WRITER VARCHAR2(10),
OUTPUT VARCHAR2(50),
PRICE NUMBER(3));
CREATE TABLE READER (
READER_ID NUMBER(3),
COMPANY VARCHAR2(10),
NAME VARCHAR2(10),
SEX VARCHAR2(2),
GRADE VARCHAR2(10),
ADDR VARCHAR2(50));
CREATE TABLE BORROW (
READER_ID NUMBER(3),
BOOK_ID NUMBER(10),
BORROW_DATE DATE);
插入数据:
BOOK表:
insert into book values(445501,'TP3/12','数据库导论','王强','科学出版社',17.90);
insert into book values(445502,'TP3/12','数据库导论','王强','科学出版社',17.90);
insert into book values(445503,'TP3/12','数据库导论','王强','科学出版社',17.90);
insert into book values(332211,'TP5/10','计算机基础','李伟','高等教育出版社',18.00);
insert into book values(112266,'TP3/12','FoxBASE','张三','电子工业出版社',23.60);
insert into book values(665544,'TS7/21','高等数学','刘明','高等教育出版社',20.00);
insert into book values(114455,'TR9/12','线性代数','孙业','北京大学出版社',20.80);
insert into book values(113388,'TR7/90','大学英语','胡玲','清华大学出版社',12.50);
insert into book values(446601,'TP4/13','数据库基础','马凌云','人民邮电出版社',22.50);
insert into book values(446602,'TP4/13','数据库基础','马凌云','人民邮电出版社',22.50);
insert into book values(446603,'TP4/13','数据库基础','马凌云','人民邮电出版社',22.50);
insert into book values(449901,'TP4/14','FoxPro大全','周虹','科学出版社',32.70);
insert into book values(449902,'TP4/14','FoxPro大全','周虹','科学出版社',32.70);
insert into book values(118801,'TP4/15','计算机网络','黄力钧','高等教育出版社',21.80);
insert into book values(118802,'TP4/15','计算机网络','黄力钧','高等教育出版社',21.80);
READER表:
insert into reader values(111,'信息系','王维利','女','教授','1号楼424');
insert into reader values(112,'财会系','李 立','男','副教授','2号楼316');
insert into reader values(113,'经济系','张 三','男','讲师','3号楼105');
insert into reader values(114,'信息系','周华发','男','讲师','1号楼316');
insert into reader values(115,'信息系','赵正义','男','工程师','1号楼224');
insert into reader values(116,'信息系','李 明','男','副教授','1号楼318');
insert into reader values(117,'计算机系','李小峰','男','助教','1号楼214');
insert into reader values(118,'计算机系','许鹏飞','男','助工','1号楼216');
insert into reader values(119,'计算机系','刘大龙','男','教授','1号楼318');
insert into reader values(120,'国际贸易','李 雪','男','副教授','4号楼506');
insert into reader values(121,'国际贸易','李 爽','女','讲师','4号楼510');
insert into reader values(122,'国际贸易','王 纯','女','讲师','4号楼512');
insert into reader values(123,'财会系','沈小霞','女','助教','2号楼202');
insert into reader values(124,'财会系','朱 海','男','讲师','2号楼210');
insert into reader values(125,'财会系','马英明','男','副教授','2号楼212');
BORROW表:
insert into borrow values(112,445501,'19-3月-2006');
insert into borrow values(125,332211,'12-2月-2006');
insert into borrow values(111,445503,'21-8月-2006');
insert into borrow values(112,112266,'14-3月-2006');
insert into borrow values(114,665544,'21-10月-2006');
insert into borrow values(120,114455,'02-11月-2006');
insert into borrow values(120,118801,'18-10月-2006');
insert into borrow values(119,446603,'12-11月-2006');
insert into borrow values(112,449901,'23-10月-2006');
insert into borrow values(115,449902,'21-8月-2006');
insert into borrow values(118,118801,'10-9月-2006');