《数据库训练题目》doc版.doc_第1页
《数据库训练题目》doc版.doc_第2页
《数据库训练题目》doc版.doc_第3页
《数据库训练题目》doc版.doc_第4页
《数据库训练题目》doc版.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

数据库训练题目在MS SQL2000pub数据库下,完成下面的作业,分别写出SQL语句。1、 查找在美国的所有出版商 select * from publishers where country=USA2、 查找在法国巴黎的出版商名字 select pub_name from publishers where country=Franceand city=Paris 3、查找所有价格大于20美元的出版物的名字select title from titles where price154、查找在2000年出版的出版物记录 select * from titles where pubdate between 2000-1-1and 2000-12-31 23:59:595、查找出版物名称中含有“computer”字样的出版物。select * from titles where title like %computer%6、查找在美国、所在州不为空的出版商记录 select * from publishers where country=USAand state is not null7、在MS SQL Server2000的pub数据库下,查找出版商的pub_id为1389的出版物的名字,价格,以及出版日期,结果按出版时间降序排列。 select title,price,pubdate from titles where pub_id=1389 order by pubdate desc8、在MS SQL Server2000的pub数据库下,查找出版商的pub_id为1389的出版物的数量,最大价格,平均价格,总价格(一种刊物一份的总价)。生成的表的列名分别为数量,最大价格,平均价格,总价格。 select count(*) 数量,max(price) 最大价格,avg(price) 平均价格,sum(price)总价格 from titles where pub_id=13899、仿照上题,查找所有出版商的出版物的数量,最大价格,平均价格,总价格,并列出各出版商的pub_id。按照出版物的数量对结果排序。select pub_id,count(*) 数量,max(price) 最大价格,avg(price) 平均价格,sum(price)总价格 from titles group by pub_idorder by 数量10、查询所有出版商的姓名,及其发行物的种类。 (一种刊物算一个种类)select pub_name,count(title)from publishers left outer join titles on publishers.pub_id=titles.pub_idgroup by pub_name11、 查询比所有的出版物平均价格高的出版物名称以及价格。 select title,price from titles where price(select avg(price) from titles)12、查询美国出版商发行的刊物名称。 select title from titles where pub_id in(select pub_id from publishers where country=USA)或 select title from titles,publishers where titles.pub_id=publishers.pub_id and country=USA13、查询比pub_id为1389的出版物所有价格都高的出版物名称,价格。select title,price from titles where priceAll(select price from titles where pub_id=1389) 查询比pub_id为1389的某一出版物价格高的出版物名称,价格。 select title,price from titles where priceany(select price from titles where pub_id=1389)14 、分别查询pub_id为0877与1389的出版物,并返回一个结果集。(用union)select * from titles where pub_id=0877 unionselect * from titles where pub_id=1389 15、在出版商中插入记录9909,大连理工大学出版社,dalian,null,china insert into publishers(pub_id,pub_name,city,state,country) values(9909,大连理工大学出版社,dalian,null,china) 或insert into publishers values(9909,大连理工大学出版社,dalian,null,china)16、将pub_id为0877与1389的出版商的出版物价格均升5美元,出版日期设为2002-09-09。update titles set price=price+5,pubdate=2002-09-09where pub_id in(1389,0877)或update titles set price=price+5,pubdate=2002-09-09where pub_id =1389or pub_id=087717、删除pub_id为9909的出版商记录delete from publishers where pub_id=990918、查询没有出版物的出版商记录 select * from publishers where pub_id not in(select distinct pub_id from titles)19、定义一个视图,反映的是各个出版商名称以及出版物数目。(不显示没有出版物的出版商)create view v_pub_counts asselect pub_name,count(*) as countfrom publishers,titleswhere publishers.pub_id=titles.pub_idgroup by pub_name20、定义一个视图,反映的是各个出版商名称以及出版物数目。(显示没有出版物的出版商)create view pubsum asselect pub_name,count(title) as pub_countfrom publishers left outer join titles on publishers.pub_id=titles.pub_idgroup by pub_name21、统计每种类型(type)刊物的刊物数目(每条titles记录为1条),并只输出刊物数目大于2的记录。select type,count(title)from titlesgroup by typehaving count(title)222、 查询出版了所有类型(type)刊物的出版商姓名。 方法一:select pub_namefrom publisherswhere not exists (select * from (select distinct type from titles) t where not exists ( select * from titles where(titles.type=t.type) and(titles.pub_id=publishers.pub_id) ) ) 方法二:select pub_namefrom publisherswhere not exists (select distinct type from titles t where not exists ( select * from titles where(titles.type=t.type) and(titles.pub_id=publishers.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论