使用SQL语句完成下列题目 您所在的位置:网站首页 查询借阅过全部图书的读者号和读者名 使用SQL语句完成下列题目

使用SQL语句完成下列题目

2024-06-26 12:08| 来源: 网络整理| 查看: 265

1、查询图书馆中所有图书的详细信息。(BookInfo表)

1

select * from bookinfo;

  

2、查询所有图书的图书编号、图书名称和图书价格。

1

select b_id 编号,b_name 名称,b_price 价格 from bookinfo

  

3、 查询所有图书的图书编号、图书名称和图书总额。

1

select b_id 编号,b_name 名称,b_price*b_quantity 价格 from bookinfo

  

4、查询所有图书的图书编号、图书名称和总价值,但希望以汉字标题图书编号、图书名称和总价值表示b_ID、b_Name和b_Price*b_Quantity。

1

select b_id 编号,b_name 名称,b_price*b_quantity 价格 from bookinfo

  

5、查询所有图书中的“刘志成”编写的图书的所有信息。

1

select * from bookinfo where b_author like '%刘志成%'

6、 查询图书类别编号为“17”,图书价格在25~30元之间的图书信息,要求以汉字标题显示图书编号、图书名称、图书类别编号和图书价格。

1

select b_id 图书编号,b_name 图书名称,bt_id 图书类别编号,b_price 图书价格 from bookinfo where bt_id = 17 and b_price between 25 and 30;

7、 查询所有入库在5年以上并且图书价格在10~20之间的图书的名称、图书作者、图书价格和入库时间(用“入库时长”表示,该列不是基本表中的字段,是计算出来的列)。

1

2

3

4

5

6

7

select b_name 图书名称,b_author 图书作者,b_price 图书价格, b_date 入库时间

 

from bookinfo

 

where ROUND(TO_NUMBER(SYSDATE - b_date))>=5

 

and b_price between 10 and 20;

  

8、 查询所有入库在5年以上并且图书价格不在10~20之间的图书的名称、图书作者、图书价格和入库时间

1

2

3

4

5

6

7

select b_name 图书名称,b_author 图书作者,b_price 图书价格, b_date 入库时间

 

from bookinfo

 

where ROUND(TO_NUMBER(SYSDATE - b_date))>=5

 

and b_price not between 10 and 20;

  

9、查询出版社编号为“001”和“003”的图书详细信息。

1

select * from bookinfo where p_id in (001,003)

  

10、查询图书名称中包含“数据库”字样的图书的详细信息。

1

select * from bookinfo where b_name like '%数据库%'

  

11、查询姓“王”且名字中有3个汉字的读者的编号、读者的姓名及可借书数量。

1

2

3

select r_id,r_name,r_quantity from readerinfo

 

where r_name like '王__';

  

12、查询暂时没有图书封面图片的图书信息。

1

select * from bookinfo where b_pricture is null;

  

13、       通过图书管理系统查询借阅图书的读者编号,如果一个读者借阅了多本图书,只需要显示一次读者编号。

1

select distinct r_id from borrowreturn;

  

14、查询前5行图书的详情信息。

1

select * from bookinfo where rownum =(select b_price from bookinfo where b_name = 'JSP程序设计案例教程')

 

order by b_price asc;

  

 

 

1

2

3

4

5

6

7

select G2.b_id 图书编号,G2.b_name 图书名称,G2.b_price 图书价格

 

from bookinfo G1 join bookinfo G2 on G1.b_name = 'JSP程序设计案例教程'

 

and G1.b_Price(select max(b_date) from bookinfo where p_id='007')

 

order by b_date desc;

  

30、针对ReadInfo表中的每一位读者,在BorrowReturn表中查找借阅过图书并且图书状态为“已还”的所有借阅信息。

1

2

3

4

5

6

7

8

9

select br_id,s_id,br_outdate,br_indate

 

from borrowreturn

 

where br_status = '已还'

 

and exists

 

(select * from readerinfo where readerinfo.r_id=borrowreturn.r_id);

  

31、求每一类别图书的平均价格,并将结果保存到数据库中。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

create table avgbookprice(

 

bt_id char(10),

 

p_avg number(7,2)

 

);

 

insert into avgbookprice(bt_id,p_avg)

 

select bt_id,avg(b_price)

 

from bookinfo

 

group by bt_id;

  

32、将图书管理系统中的图书出版社名称为“机械工业出版社”的图书的数量加1.

1

2

3

4

5

update bookinfo set b_quantity=b_quantity + 1

 

where p_id = (select p_id from publisher

 

where p_name = '机械工业出版社');

  

33、删除出版社名称为“机械工业出版社”的所有图书信息。

1

2

3

4

5

delete from bookinfo

 

where p_id =

 

(select p_id from publisher where p_name = '机械工业出版社')



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有