各位同仁:
   我有一个问题求教:
   有如下一数据表
--------------------------------------
  编号    姓名    科室     学历
  001     张三    财务     中专    
  002     李四    财务     大专    
  003     王五    商务     本科   
  004     李二    商务     大专  
  005     吴立    商务     中专
  006     钱明    设备     本科
--------------------------------------
现在我要求统计如下的结果:
--------------------------------------
  科室    中专     大专    本科 
--------------------------------------
  财务     1       1      
  商务             2        1
  设备                      1
--------------------------------------
请那位指点一下如何写这句SQL。    

解决方案 »

  1.   

    select 科室,
    (select count(*) from table b where a.科室 = b.科室 and 学历 = '中专'),
    (select count(*) from table b where a.科室 = b.科室 and 学历 = '大专'),
    (select count(*) from table b where a.科室 = b.科室 and 学历 = '本科')
    from table a
    group by 科室
      

  2.   

    select 科室,(select count(*) from table where 学历='中专'),
     (select count(*) from table where 学历='大专'),
     (select count(*) from table where 学历='本科')
     from table group by 科室
      

  3.   

    我用的是ACCESS数据库,依楼上的写法为什么行不通??
      

  4.   

    select distect(科室), 
    (select count(*) from table b where a.科室 = b.科室 and 学历 = '中专'),
    (select count(*) from table b where a.科室 = b.科室 and 学历 = '大专'),
    (select count(*) from table b where a.科室 = b.科室 and 学历 = '本科')
    from table a
    group by 科室
    distect是不是这样拼我都忘了,自己查一下吧?
      

  5.   

    “distect” 应为“distinct”
      

  6.   

    使用delphi的TDecisionCube可以解决你的问题,它支持n维的报表统计功能
      

  7.   

    我是新手,有点不明白,请问:
    1. table a和table b代表什么呢?
    2. 我只有一个表名,那怎么办啊?
      

  8.   

    我是新手,有点不明白,请问:
    1. table a和table b代表什么呢?
    2. 我只有一个表名,那怎么办啊?