select * from 表 t
where 单价>(select avg(单价) from 表 where 书籍类别=t.书籍类别)

解决方案 »

  1.   

    declare @tb table
    (
      书籍编号 int,
      书名  varchar(20),
      书籍类别 int,
      单价 decimal(12,4)
    )
    insert @tb               
    select 1,          'SQL Server指南',        1,           50.0000 union all
    select 2,          'VISUAL Basic指南',      1,           30.0000 union all
    select 3,          'VISUAL C++编程',       2 ,          60.0000 union all
    select 4,          'INTERDEV完全手册',      2 ,          50.0000 union all
    select 5,          'ORACLE 8I参考',         2 ,          50.0000  union all
    select 6,          'AUTHWARE指南',          2,           40.0000 union all
    select 7,          'AUTHWARE指南',          5,           10.0000  union all          
    select 8,          '3DMAX使用指南',         5 ,          10.0000 union all
    select 9,          'ASP指南',               5,           10.0000 union all
    select 10,         'JSP指南',               5 ,          30.0000--查询
    select * from @tb t
    where 单价>(select avg(单价) from @tb where 书籍类别=t.书籍类别)--结果
    /*
    书籍编号        书名                   书籍类别        单价             
    ----------- -------------------- ----------- -------------- 
    1           SQL Server指南         1           50.0000
    3           VISUAL C++编程         2           60.0000
    10          JSP指南                5           30.0000(3 row(s) affected)
    */