当前位置: 代码迷 >> Sql Server >> 如何加入判断条件
  详细解决方案

如何加入判断条件

热度:36   发布时间:2016-04-27 12:23:19.0
怎么加入判断条件!
SQL code
  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的记录!

怎么加啊



------解决方案--------------------
SQL code
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
------解决方案--------------------
SQL code
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 = 1GROUP BY Lidhaving sum(case when TID>=1 and TID <=10 then 1 else 0 end) > N
------解决方案--------------------
SQL code
;with [temps] as(select row_number()over(PARTITION BY LID order by RID desc) as TID,gLid,result from results)select Lid,sum(case when Tid>=1 and TID<=10 then 1 else 0 end) as [c010]from temps where Result=1group by Lidhaving 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 字句功能确实很强大,学习了!
------解决方案--------------------
学习一下,都是几十年的语言了,强大是必须的
------解决方案--------------------
SQL code
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 Lidhaving sum(case when TID>=1 and TID <=10 then 1 else 0 end)>N
  相关解决方案