select count(sex),sex from table group by sex
回家耍去也

解决方案 »

  1.   

    可以按所需的格式建一个表,分别用sql查处每个数据在写入表中,在用报表就可以打印。每次打印前将表清空,sql语法同楼上所说
      

  2.   

    你男女和农民居民又不再一个字段里,无法使用group by语句,谁不想一句话写完
      

  3.   


    这样写,
    select
    count(*) 总人数 ,
    sum(decode(xb,'男',1)) 男性,
    sum(decode(xb,'女',1)) 男性,
    sum(decode(yglb,'工人',1)) 工人,
    sum(decode(yglb,'干部',1)) 干部
    from t_ygjbxx
    SQL SERVER 中用IIF 代替DECODE
      

  4.   

    select count(aID) "总人数",Sum(Case when sex='男' then 1 end) "男性",Sum(Case When sex='女' then 1 end) "女性",Sum(Case when work='工人' then 1 end) "工人",Sum(Case when Work='干部' then 1 end) "干部" from table
      

  5.   

    上面的语句不行
    SUM好像只能对数值进行统计
      

  6.   

    ACCESS中好像也有类似的函数,如果还不行,这样写,不用函数:
    select A.*,B.*,C.*,D.*,E.* FROM
    (select count(*) 总人数 from t_ygjbxx)A,
    (select count(*) 男性 from t_ygjbxx where xb='男')B,
    (select count(*) 女性 from t_ygjbxx where xb='女')C ,
    (select count(*) 干部 from t_ygjbxx where yglb='干部')D,
    (select count(*) 工人 from t_ygjbxx where yglb='工人')E
      

  7.   

    Access数据库不行,很多都不能用
      

  8.   

    原来是三张表,表结构不太清楚,可以把表结构发到我的邮箱,我试试!
    [email protected]