with [temps] as
    (
    select row_number() over(PARTITION BY LID order by RID Desc) as TID,LID,Result  from Results
    )
     select Lid,sum(case when TID>=1 and TID <=10 then 1 else 0 end) as [C010]
           
    from temps where Result = 1 
    
    GROUP BY Lid上面的语名中,判断C010大于N的记录!怎么加啊

解决方案 »

  1.   


    with [temps] as
        (
        select row_number() over(PARTITION BY LID order by RID Desc) as TID,
        LID,Result  from Results
        )
         select Lid,sum(case when TID>=1 and TID <=10 then 1 else 0 end) as [C010]
               
        from temps where Result = 1     GROUP BY Lid
        having sum(case when TID>=1 and TID <=10 then 1 else 0 end)>N
      

  2.   

    with [temps] as
        (
        select row_number() over(PARTITION BY LID order by RID Desc) as TID,LID,Result  from Results
        )
    select Lid,sum(case when TID>=1 and TID <=10 then 1 else 0 end) as [C010]       
    from temps 
    where Result = 1
    GROUP BY Lid
    having sum(case when TID>=1 and TID <=10 then 1 else 0 end) > N
      

  3.   

    ;with [temps] as
    (select row_number()over(PARTITION BY LID order by RID desc) as TID,g
    Lid,result from results
    )
    select Lid,sum(case when Tid>=1 and TID<=10 then 1 else 0 end) as [c010]
    from temps where Result=1
    group by Lid
    having sum(case when Tid>=1 and Tid<=10 then 1 else 0 end)>N
      

  4.   

    sql 语句博大精深哈,row_number()over(PARTITION BY LID order by RID desc)类似的几种用法昨天做报表时第一次用到,呵呵感觉不错哈。
      

  5.   


    with [temps] as
    (
    select row_number() over(PARTITION BY LID order by RID Desc) as TID,LID,Result  
    from Results
    )
    select Lid,sum(case when TID>=1 and TID <=10 then 1 else 0 end) as [C010]
    from temps where Result = 1 
    GROUP BY Lid
    having sum(case when TID>=1 and TID <=10 then 1 else 0 end)>N