是用SQL SERVER写的
小弟初学~~麻烦大家了哈~

解决方案 »

  1.   


    --1
    select r.读者号, r.读者姓名, b.书名, count(j.书号) as 借阅本数
    from 读者表 r
      inner join 借阅表 j on r.读者号=j.读者号
      inner join 图书表 b on b.书号=j.书号
    where 出版社='机械工业出版社'
    group by j.读者号
    having count(j.书号)>1
    order by count(j.书号) desc--2
    select 书名, 单价
    from 图书表
    where 出版社='科学出版社' and 单价>
    (
    select max(单价)
    from 图书表
    where 出版社='机械工业出版社'
    )--3
    select 书名, 单价
    from 图书表
    where 出版社='科学出版社' and 单价>
    (
    select min(单价)
    from 图书表
    where 出版社='机械工业出版社'
    )
      

  2.   

    后两个还可以写成
    --2
    select 书名, 单价
    from 图书表
    where 出版社='科学出版社' and 单价 >all
    (
    select 单价
    from 图书表
    where 出版社='机械工业出版社'
    )--3
    select 书名, 单价
    from 图书表
    where 出版社='科学出版社' and 单价>any
    (
    select 单价
    from 图书表
    where 出版社='机械工业出版社'
    )
      

  3.   

    2.查询‘科学出版社’的图书单价比‘机械工业出版社’最高单价还高的图书书名及单价 
    select * from  图书表 T  where 单价>(select max(单价) from 图书表 where 出版社='机械工业出版社') And  出版社='科学出版社'
      

  4.   

    1.
    select 
      b.读者号,b.姓名,a.书名,count(c.书号)
    from
      图书表 a,读者表 b,借阅表 c
    where 
      a.书号=c.书号 and b.读者号=c.读者号
    and 
      a.出版社='机械工业出版社'
    group by 
      b.读者号,b.姓名
    having
      count(c.书号)>1
    order by
      3 desc
      

  5.   

    --2
    select
     书名, 单价
    from
     图书表
    where
     出版社='科学出版社' and 单价>(select max(单价) from 图书表 where 出版社='机械工业出版社')--3
    select
     书名, 单价
    from
     图书表
    where
     出版社='科学出版社' 
    and 
     单价>(select min(单价) from 图书表 where 出版社='机械工业出版社')
      

  6.   

    我发现第1题有点问题,如果1个读者借过两本书,那它的书名将无法都写出来,如果没有书名那列的话,应该写成:
    --1
    select j.读者号, r.姓名, count(j.书号) as 借阅本数
    from 读者表 r
      inner join 借阅表 j on r.读者号=j.读者号
      inner join 图书表 b on b.书号=j.书号
    where 出版社='机械工业出版社'
    group by j.读者号, r.姓名
    having count(j.书号)>1
    order by count(j.书号) desc
      

  7.   

    服务器: 消息 8120,级别 16,状态 1,行 1
    列 'a.书名' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。其实这个书名是无法在这道题中显示出来的,觉得题出错了