表user   表内username,type两列,username是用户名,type是权限。 表type   表内有type权限名,不能重复有约束 表user有数据 admin   超级管理员 
abc   超级管理员 
test   普通会员 表type有数据 超级管理员 
普通会员 现在要求查询出一张虚拟表显示信息如下 
权限名             会员数 
超级管理员     2 
普通会员         1

解决方案 »

  1.   

    select 权限名=T.type权限名, 会员数=isunll(count(username),0)
    from type T left join [user] U on T.type权限名=U.type
      

  2.   

    --掉了个group by
    select 权限名=T.type权限名, 会员数=isunll(count(username),0)
    from type T left join [user] U on T.type权限名=U.type
    group by 权限名
      

  3.   

    --掉了个group by
    select 权限名=T.type权限名, 会员数=isnull(count(username),0)
    from type T left join [user] U on T.type权限名=U.type
    group by 权限名