解决方案 »

  1.   

    select *,(select count(1) from 表名 where a.岗位=岗位) from 
    表名 a
      

  2.   

    select *,count(1) over(partition by 岗位) from 表名
      

  3.   


    count(1) over(partition by 岗位)能解释下这代码的意思吗?
      

  4.   


    count(1) over(partition by 岗位)能解释下这代码的意思吗?好像是05 还是 08 对聚合函数的一个新的用法吧
      

  5.   


    count(1) over(partition by 岗位)能解释下这代码的意思吗?好像是05 还是 08 对聚合函数的一个新的用法吧还有其他的函数可以实现吗?
      

  6.   

    over()窗口函数,不用连接的话,貌似只能这样;
      

  7.   

    连接这么好用,为啥不用?
    if object_id('[tb]') is not null drop table [tb]
    gocreate table tb (员工号 int  ,   姓名 varchar(10),   岗位 varchar(10),        上级员工号 varchar(10))
    insert into tb
    select '1','a','程序猿','6'union all                    
    select '2','b','测试猿','7'union all                    
    select '3','c','程序猿','6'union all                    
    select '4','d','测试猿','7'union all                    
    select '5','e','程序猿','6'union all                    
    select '6','f','经理',''   union all                    
    select '7','g','经理',''                                select  a.*,b.数目 from tb a left join (select  岗位, count(岗位) as 数目 from tb group by 岗位) bon a.岗位=b.岗位--员工号 姓名 岗位 上级员工号 数目
    --1 a 程序猿 6 3
    --2 b 测试猿 7 2
    --3 c 程序猿 6 3
    --4 d 测试猿 7 2
    --5 e 程序猿 6 3
    --6 f 经理 2
    --7 g 经理 2