`
qinya06
  • 浏览: 582226 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

sql 3

    博客分类:
  • sql
SQL 
阅读更多
select smallRfunctions  from ( SELECT smallRfunctions,count(resDepart) as num FROM paCuAssessment
 where  datediff(m,subDate,getDate())=0 group by bigRfunctions, smallRfunctions) m
where m.num >=(SELECT coeffValue
FROM PaCoefficient
WHERE (item = '责任部门下限'))


一个职能大项对应多个小项,一个小项对应多个职能部门,需求:根据职能小巷的职能部门数目分组
===================================================================================

select * from dbo.PAtaskDataEntry where alarmScope is not null and datediff(m,taskDate,getdate())=1 and 

convert(numeric(8,2),currentData) < convert(numeric(8,2),substring(alarmScope,0,charindex('-',alarmScope))) or

convert(numeric(8,2),currentData)>  convert(numeric(8,2),substring(alarmScope,charindex('-',alarmScope)+1,len(alarmScope)))


=======================================================================================


--创建示例表
declare @t table (c1 int,c2 int,c3 int,c4 int)
insert @t select 1,2,3,0
union all select 1,3,2,0
union all select 3,1,2,0


--查询语句
update @t set c4=(
case when c1>c2 and c1>c3 then c1
     when c2>c1 and c2>c3 then c2
     else c3 end 
)


===========================================================================================================
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics