楼主你的
groupnull和proportion是怎么来的可以说一下吗?

解决方案 »

  1.   

    select *,(select count(*) as groupnull,count(*)/(select count(*) from tbclient) as proportion
    from tbclient where groupID = bclientgroup.groupID)
    from bclientgroup
      

  2.   


    select *,(select count(*) as groupnull,
            count(*)/(select count(*) from tbclient) as proportion
      from tbclient 
      where tbclient.groupID = bclientgroup.groupID)
    from bclientgroup
      

  3.   

    select a.groupID,a.groupname
    ,groupnull=count(b.clientID)
    ,proportion=case (select count(*) from tbclient)
    when 0 then '0%'
    else cast(cast(
    count(b.clientID)*100.0
    /(select count(*) from tbclient)
    as decimal(10,2)) as varchar)+'%' end
    from tbclientgroup a
    left join tbclient on a.groupID=b.groupID
    group by a.groupID,a.groupname