数据库原理实验报告 - 图文 下载本文

实验二 表查询

一 实验要求

根据给定的样例数据库pubs,完成以下查询操作。 1、无条件查询

1) 查找pub库中authors表的全部信息。 2) 查找其他样例表中全部信息。 2、简单条件查询

1) 查找titles表中全部书号及书名。

2) 查找titles 表中价格在$15~18 元之间的书的书名。 3) 查找titles 表中书名以T 开头的书号, 书名。 4) 对其他样例表构造各种简单查询条件,进行查询。 3、多条件查询

1) 查找书名起始字符为T,价格小于$16元的书名及价格。

2) 查找书名起始字符不为T的, 价格大于$16元的书号, 书名及价格。 3) 对其他样例表构造多个查询条件,进行查询。 4、用连接操作(或嵌套查询)进行查询

1) 使用样例表titles, publishers 进行查询: 查找出版社的名称以及所出的书名。

2) 使用样例表authors, titleauthor, titles进行查询: 查找作者的姓、名和所写的书名。

3) 对构造其他条件,在两个以上样例表中进行查询。 5、得到排序的查询结果

1)查找作者的姓、名、电话号码,并按作者姓、名排列。 2)查找书名和书的价格,按书价由大到小的次序排列。 3)对其他样例表构造查询条件、排序要求,给出查询结果。

13

6、使用函数进行查找

1)列出有多少类书。 2)列出书的定价有多少种。 3)列出书价最低的书名和书价。 4)查出书价最高的书名及书价。 5)列出当年销量的总和。

6)构造其他查询条件和统计要求,给出查询结果。

二 实验结果

select *

from authors

select *

from discounts

select * from sales

select * from titles

select *

from employee

select * from jobs

select *

from pub_info

select *

from publishers

select *

from roysched

select *

14

from stores

select *

from titleauthor

select title_id,title from titles

select title from titles

where price>15 and price<18

select title_id,title from titles

where title like 'T%'

select title_id,title,pub_id from titles

where pub_id<1000

select price,title from titles

where price<16 and title like 'T%'

select title_id,title,price from titles

where title not like 'T%' and price>16

select title_id,title,price from titles

where title not like 'T%' and price<=16

select pub_name,title from titles,publishers

where titles.pub_id=publishers.pub_id

select au_lname,au_fname,title from authors,titleauthor,titles

where titles.title_id=titleauthor.title_id and titleauthor.au_id=authors.au_id

select city,title

15

from titles,publishers

where titles.pub_id=publishers.pub_id

select au_fname,au_lname,phone from authors

order by au_fname,au_lname

select title,price from titles

order by price desc

select title,price from titles

order by price asc

select COUNT(distinct type) as 书的种类 from titles

select COUNT(distinct price) as 定价种类 from titles

select title,price from titles

where price=(select min(price)from titles)

select title,price from titles

where price=(select max(price)from titles)

16