数据库原理-SQL简单查询

  • 格式:docx
  • 大小:127.59 KB
  • 文档页数:4

计算机工程学院实验报告

2017-2018学年第1学期

课程名称: 数据库原理

专 业: 计算机科学与技术

班 级: 2班

学 号:

姓 名:

指导教师:

实验名称:SQL简单查询

实验日期:2017.10.18

实验平台:Windows 7 + SQL Server 2008

实验目的 1. 熟练掌握单表查询的SELECT语法结构;

2. 通过观察查询结果, 体会SELECT语句的实际应用。

实验内容与完成情况

3.1 查询1991年出生的读者姓名、工作单位和身份证号。

select readername,workunit,identifycard

from Reader

/*where identifycard like '%1991%'*/

/*where substring(identifycard,7,4)=1991*/

where identifycard like '______1991%'

3.2 查询在信息管理学院工作的读者编号、姓名和性别。

select readerno,readername,sex

from Reader

where workUnit like '信息管理学院'

3.3 查询图书名中含有“数据库”的图书的详细信息。

select *

from Book

where bookName like '%数据库%'

3.4 查询吴文君老师编写的单价不低于40元的每种图书的图书编号、入库数

量。 select bookno,shopnum from Book

where authorName='吴文君' and price>=40

3.5 查询在1995年入库的图书编号、出版时间、入库时间和图书名称,并按入库时间排序输出。

select bookno,publishingdate,shopdate,bookname

from Book

where year(shopdate)=1995

order by shopDate

3.6 查询借阅了B200201002图书编号的读者编号、图书编号、借书日期。

select readername,borrowdate,returndate

from Reader a,Borrow b

where a.readerno=b.readerno and b.bookNo='B200201002'

3.7 查询读者马永强借阅的图书编号、图书名称、借书日期和归还日期。

select c.bookno,bookname,borrowdate,returndate

from Book a,Reader b,Borrow c

where b.readerName='马永强' and a.bookNo=c.bookno and

b.readerno=c.readerno

3.8 查询信息管理学院没有归还图书的读者编号、读者姓名、图书名称、借书日期和应归还日期。

select c.readerno,readername,bookname,borrowdate,shoulddate

from book a,borrow b,reader c

where a.bookno=b.bookno and b.readerno=c.readerno and returndate is Null and workunit='信息管理学院'

3.9 查询借阅了清华大学出版社出版的图书的读者编号、读者姓名、图书名称、借书日期和归还日期。

Select b.readerno,readername,bookname,borrowdate,returndate

From book a,borrow b,reader c

Where a.bookno=b.bookno and b.readerno=c.readerno and publishingname='清华大学出版社'

3.10 查询借书时间在2011年的读者编号、姓名、图书编号、图书名称。

select b.readerno,readername,a.bookno,bookname

from book a,borrow b,reader c

Where a.bookno=b.bookno and b.readerno=c.readerno and

year(borrowDate)=2011

出现的问题及解决方案

实验中我对于表的连接所采用的SQL语言不是太熟悉,编写过程中容易出错。本次实验让我对SELECT语句的应用有了更深的理解,掌握了当某个属性的取值为空时的“* is null”的用法,同时加深了我对SELECT语句的记忆和掌握。

教师评阅意见

成绩: 教师签名: 日期: