Select 维修人,维修编码,Cast((a.次数/(tmp.次数+0.00)) as decimal(8,2)) as 次数 from (Select 维修编码,次数=Count(*) from table Group by 维修编码)tmp,table a where tmp.维修编码=a.维修编码

解决方案 »

  1.   

    select 维修人,维修编码,count(*) from table group by 维修人,维修编码
      

  2.   

    declare @tb table(单据号 varchar(10),维修人 varchar(20),维修编码 varchar(10))
    insert @tb values('b1','001','101')
    insert @tb values('b1','002','101')
    insert @tb values('b2','001','201')
    insert @tb values('b2','002','201')
    insert @tb values('b2','003','201')
    select 维修人,维修编码 ,(select cast(1/cast(count(*) as numeric(10,2)) as numeric(5,2))  from @tb where  单据号=tmp.单据号) as 次数
    from @tb as tmp
    ---------------
    维修人    维修编码     次数
    001 101 .50
    002 101 .50
    001 201 .33
    002 201 .33
    003 201 .33
      

  3.   

    Select a.维修人,a.维修编码,Cast((1/(tmp.次数+0.00)) as decimal(8,2)) as 次数 from (Select 维修编码,次数=Count(*) from 表名 Group by 维修编码)tmp,表名 a where tmp.维修编码=a.维修编码
      

  4.   

    select  维修人, 维修编码, 
    (select cast(1/count(*) as decimal(8,2)) from yourtable 
              where 单据号 = A.单据号) 次数 from yourtable A
    order by 维修编码, 维修人
      

  5.   

    select 维修人,维修编码,cast(sum(1)/(select sum(1)+0.0 from 你的表 where 单据号 in (select 单据号 from 你的表 where 维修人=tem.维修人 and 维修编码=tem.维修编码)) as numeric(10,2)) 次数 from 你的表 tem group by 维修人,维修编码