当前位置: 代码迷 >> Sql Server >> 怎么把group by的count中的每个peronid读出
  详细解决方案

怎么把group by的count中的每个peronid读出

热度:74   发布时间:2016-04-27 16:26:54.0
如何把group by的count中的每个peronid读出?
我的SQL如下:
select   A.streetname,A.bn2,A.bn1,A.cnt,A.sfe,B.bn2,B.bn1,B.cnt,B.sfe   from
      (select   t.streetname,s2.cdtxt   as   bn2,s1.cdtxt   as   bn1,count(distinct   personid)   cnt,sum(Fee)   sfe  
      from   social.grantdetail   g
      inner   join   sqdta.sqcode   s1   on   g.branch1=s1.cdcode
      inner   join   sqdta.sqcode   s2   on   g.branch2=s2.cdcode
      inner   join   sqdta.street   t   on   g.street1=t.streetid
      where   g.commid1 <> g.commid2   and   branch2= '01 '   and   s1.cdtype= 'STREET.BRANCHID '   and   s2.cdtype= 'STREET.BRANCHID '
      group   by   t.streetname,s2.cdtxt,s1.cdtxt)A,
      (select   t.streetname,s2.cdtxt   as   bn2,s1.cdtxt   as   bn1,count(distinct   personid)   cnt,sum(Fee)   sfe  
      from   social.grantdetail   g
      inner   join   sqdta.sqcode   s1   on   g.branch1=s1.cdcode
      inner   join   sqdta.sqcode   s2   on   g.branch2=s2.cdcode
      inner   join   sqdta.street   t   on   g.street1=t.streetid
      where   g.commid1 <> g.commid2   and   branch1= '01 '   and   s1.cdtype= 'STREET.BRANCHID '   and   s2.cdtype= 'STREET.BRANCHID '
      group   by   t.streetname,s2.cdtxt,s1.cdtxt)B
where   A.streetname   =   B.streetname;

现在我要把每个group   by的count(personid)中的每个personid读出
如何实现?

比如count(personid)=3
则把:
0001
0002
0003读出?

------解决方案--------------------
看不大明白
有沒有測試數據啊?
  相关解决方案