多条件复合分组统计报表-->>请进
各位高手们,小生最近在做一个人事管理系统,采用的是FASTREPORT3.10报表工具。其中一个统计表如下表所示。所有数据字段出自同一张表中。每一个单元格中都需要统计其相应的人数,其中 局级 处级  科级 副局级 属于同一字段,研究生  本科生     专科    属于同一字段。每个单元格内只需要统计的人数。
 
 女 党员 本科 硕士 专科 总计 
局级       
处级       
科级       
副局级            我现在能想到的办法就只有利用变量传递查询值。但觉得这么做每一个单元格都是一个多条件的查询。这样做下来实在是没有什么实际操作的意义。希望各位大大们在看到之后给我一点可行性的意见。先在这里谢谢你们了。

解决方案 »

  1.   

    把表结构写出来,大家可以写一些参考的SQL语句的。
      

  2.   

    这里所需要的内容只有一张表‘EMPLOYEE’:人员编号、姓名、性别、身份证号、出生年月、民族、政治面貌、入党派时间、文化程度、毕业院校、毕业时间、所学专业、现职务、待遇级别、现工作单位、技术职称、所在部门、参加工作时间、人员分类;
      

  3.   

    select * into EMPLOYEE1 from
    (
    select '001' as 编号,'张三' as 姓名,'女' as 性别,'党员' as 政治面貌,'本科' as 文化程度,'局级' as 待遇级别 
    union
    select '002' as 编号,'李四' as 姓名,'女' as 性别,'党员' as 政治面貌,'本科' as 文化程度,'局级' as 待遇级别 
    union
    select '003' as 编号,'王五' as 姓名,'女' as 性别,'党员' as 政治面貌,'本科' as 文化程度,'处级' as 待遇级别 
    union
    select '004' as 编号,'线六' as 姓名,'女' as 性别,'党员' as 政治面貌,'本科' as 文化程度,'副局级' as 待遇级别 )
    xselect * from employee1select x.待遇级别, (select count(*) from employee1 where 待遇级别=x.待遇级别 and 性别='女') as 女,
    (select count(*) from employee1 where 待遇级别=x.待遇级别 and 政治面貌='党员') as 党员,
    (select count(*) from employee1 where 待遇级别=x.待遇级别 and 文化程度='本科') as 本科,
    (select count(*) from employee1 where 待遇级别=x.待遇级别 and 文化程度='硕士') as 硕士,
    (select count(*) from employee1 where 待遇级别=x.待遇级别 and 文化程度='专科') as 专科,
    (select count(*) from employee1 where 待遇级别=x.待遇级别 ) as 合计
    from
    (select distinct 待遇级别 from employee1) x
    --运行结果
    处级  1 1 1 0 0 1
    副局级1 1 1 0 0 1
    局级  2 2 2 0 0 2
      

  4.   

    枫叶大大,这就是最后的SQL语句吗?我直接拿到了ADOQUERY中运行了一下,提示为:FROM子句错误。以前没有用到如此复杂的SQL语句,请给小弟整理一下行吗?
      

  5.   

    你在SQL查询分析器试试,一定可以,以前我把employee 写成 employee1,你可能没有修改!
    select x.待遇级别, (select count(*) from employee where 待遇级别=x.待遇级别 and 性别='女') as 女,
    (select count(*) from employee where 待遇级别=x.待遇级别 and 政治面貌='党员') as 党员,
    (select count(*) from employee where 待遇级别=x.待遇级别 and 文化程度='本科') as 本科,
    (select count(*) from employee where 待遇级别=x.待遇级别 and 文化程度='硕士') as 硕士,
    (select count(*) from employee where 待遇级别=x.待遇级别 and 文化程度='专科') as 专科,
    (select count(*) from employee where 待遇级别=x.待遇级别 ) as 合计
    from
    (select distinct 待遇级别 from employee) x