2 dqlstp dqlstp 于 2015.07.20 10:49 提问

我这个sql语句会产生阻塞甚至死锁,请高手看看啦,sql2000

select top 1 RelHumi, ydatetime

from [zsqxdb].[dbo].[YCZ_Minutes_Data_New]
where RelHumi =(
SELECT max(RelHumi) FROM [zsqxdb].[dbo].[YCZ_Minutes_Data_New]
where (year(ydatetime)=year(getdate()))
and (month(ydatetime)=month(getdate()))
and (day(ydatetime)=day(getdate()))
and (datename(HH,ydatetime)=datename(HH,getdate()))
)
and (year(ydatetime)=year(getdate()))
and (month(ydatetime)=month(getdate()))
and (day(ydatetime)=day(getdate()))
and (datename(HH,ydatetime)=datename(HH,getdate()))

就是查询RelHumi在这个小时最大的那个数据和时间,最近老是有死锁,不知道为什么,如何修改

2个回答

CSDNXIAON
CSDNXIAON   2015.07.20 10:53

SQL死锁-阻塞
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

fang2020
fang2020   2015.07.20 15:36

SELECT top 1 max(RelHumi) as RelHumi, ydatetime FROM [zsqxdb].[dbo].[YCZ_Minutes_Data_New]
where (year(ydatetime)=year(getdate()))
and (month(ydatetime)=month(getdate()))
and (day(ydatetime)=day(getdate()))
and (datename(HH,ydatetime)=datename(HH,getdate()))

Csdn user default icon
上传中...
上传图片
插入图片