首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

如何加入判断条件

2012-06-14 
怎么加入判断条件!SQL codewith [temps] as(select row_number() over(PARTITION BY LID order by RID Des

怎么加入判断条件!

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 

热点排行