SQL查询语句 常用示例

SQL语言的应用

1、     找出姓李的读者姓名和所在单位。

2、     列出图书库中所有藏书的书名及出版单位。

3、     查找高等教育出版社的 所有图书及单价,结果按单价降序排序。

4、     查找价格介于10元和20元之间的图书种类,结果按出版单位和单价升序排序。

5、     查找书名以计算机打头的所有图书和作者。

6、     检索同时借阅了总编号为112266和449901两本书的借书证号。

7、     查找所有借了书的读者的姓名及所在单位。

8、     找出李某所借图书的所有图书的书名及借书日期。

9、     查询1997年10月以后借书的读者借书证号、姓名和单位。

10、  找出借阅了FoxPro大全一书的借书证号。

11、  找出与赵正义在同一天借书的读者姓名、所在单位及借书日期 。

12、  查询1997年7月以后没有借书的读者借书证号、姓名及单位。

13、  学会利用导出的方法创建图书管理数据库并完成下面SQL高级查询:

14、  求科学出版社图书的最高单价、最低单价、平均单价。

15、  求信息系当前借阅图书的读者人次数。

16、  求出各个出版社图书的最高价格、最低价格和册数。

17、  分别找出各单位当前借阅图书的读者人数。

18、  找出当前至少借阅了2本图书的读者及所在单位。

19、  分别找出借书人次超过1人次的单位及人次数。

20、  找出藏书中各个出版单位的册数、价值总额。

21、查询经济系是否还清所有图书。如果还清,显示该系所有读者的姓名、所在单位和职称。

1  select 姓名,单位 from 读者 where 姓名 like '李%'
2  select 书名,出版单位 from 图书
3  select 书名,单价 from 图书 where 出版单位 = '高等教育出版社' order by 单价 desc
4  select 分类号 from 图书 where 单价 >10 and 单价<20 order by 出版单位,单价
5  select 书名,作者 from 图书 where 书名 like '计算机%'
6  select jy1.借书证号 from 借阅 jy1,借阅 jy2 where jy1.总编号='112266' and jy2.总编号='449901' and jy1.借书证号=jy2.借书证号
7  select distinct 姓名,单位 from 读者,借阅 where 读者.借书证号=借阅.借书证号
8  select distinct 书名,姓名,借书日期 from 读者,借阅,图书 where  读者.姓名 like '李%' and 读者.借书证号=借阅.借书证号 and 借阅.总编号=图书.总编号
9  select   distinct 借阅.借书证号,姓名,单位 from 借阅,读者 where 借阅.借书日期>='1997-10-01' and 借阅.借书证号=读者.借书证号
10 select 借书证号,书名 from 借阅,图书 where 图书.书名='FoxPro大全' and 图书.总编号=借阅.总编号
11 select 姓名,单位,借书日期 from 读者 ,借阅 where 借阅.借书证号=读者.借书证号 and 借阅.借书日期 in (select 借书日期 from 读者,借阅 where 读者.姓名='赵正义' and 读者.借书      证号=借阅.借书证号)
12 select distinct 借阅.借书证号,姓名,单位 from 借阅,读者 where 借阅.借书证号=读者.借书证号 and 借阅.借书日期<'1997-7-01'
13 select 出版单位, Max(单价)最高单价,Min(单价)最低单价,Avg(单价)平均单价 from 图书  where 出版单位='科学出版社'group by 出版单位
14 select count(DISTINCT 借阅.借书证号)人数 from 读者,借阅 where 读者.单位='信息系' and 读者.借书证号=借阅.借书证号 
15 select 出版单位, Max(单价)最高价格,Min(单价)最低价格,count(出版单位)册数 from 图书 group by 出版单位 order by count(出版单位)
16 select 单位,count(*)人数 from 读者,借阅 where 读者.借书证号=借阅.借书证号 group by 读者.单位
17 select 单位,count(*)人数 from 读者 where 读者.借书证号 in (select 借书证号 from 借阅) group by 单位 
18 select 姓名,单位 from 读者,借阅 where 读者.借书证号=借阅.借书证号 group by 姓名,单位 Having count(借阅.借书证号) >=2
19 select 单位,count(*)次数 from 读者 where 读者.借书证号 in (select 借书证号 from 借阅 ) group by 单位 Having count(*)>1
20 select 出版单位,count(出版单位)册数 ,sum(单价)总价 from 图书 group by 出版单位
21 if exists (select 读者.借书证号 from 读者,借阅 where 读者.单位='经济系' and 读者.借书证号=借阅.借书证号) select '0'  else select 姓名,单位,职称 from 读者 where 读者.   单位='经济系'

 

posted @ 2016-08-09 15:42  苦力劳动者  阅读(8548)  评论(0编辑  收藏  举报