我用三个字段保存人员记录
怎么同事统计出三个字段的人员
我知道一个字段的是下面的语句
那三个字段的怎么统计
StrSql = "select RY ,count(*) as 记录数 from t_input GROUP BY RY"

解决方案 »

  1.   

    StrSql = "select RY ,ry1,ry2,count(*) as 记录数 from t_input GROUP BY RY,ry1,ry2"
    这先按ry,再按ry1,ry2统计,ry  是大组,ry1,ry2是小组!我不知道你的具体意思.下面统计有重复的,一条记录可能被重复统计
    select RY as 字段,count(*) as 记录数 from t_input GROUP BY RY"
    union 
    select RY1 as 字段,count(*) as 记录数 from t_input GROUP BY RY1"
    union
    select RY2 as 字段,count(*) as 记录数 from t_input GROUP BY RY2"
      

  2.   

    StrSql = "select RY ,count(*) as 记录数1,RY2,count(*) as 记录数2,RY3,count(*) as 记录数3 from t_input GROUP BY RY,RY1,RY2"
      

  3.   

    赞同 ghostzxp(幽灵) 的方法,然后可以建一个视图