日期:2014-05-18 浏览次数:20459 次
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
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
------解决方案--------------------
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
------解决方案--------------------
;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
------解决方案--------------------
sql 语句博大精深哈,row_number()over(PARTITION BY LID order by RID desc)类似的几种用法昨天做报表时第一次用到,呵呵感觉不错哈。
------解决方案--------------------
PARTITION BY 字句功能确实很强大,学习了!
------解决方案--------------------
学习一下,都是几十年的语言了,强大是必须的
------解决方案--------------------
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