我有以下语句
select pkid
from AttendancePosting
where datename(dw,AttDate) = 'Sunday' and empid=4 and attdate='2015-12-13'
group by PKId,timeout
--having 9=9
having cast(sum((datepart(minute, timeout)))/2 as float )+''=cast(datepart(minute,timeout) as float) +''
问题是
having cast(sum((datepart(minute, timeout)))/2 as float )+''=cast(datepart(minute,timeout) as float) +''
不起作用。cast(sum((datepart(minute, timeout)))/2 as float )
和cast(datepart(minute,timeout) as float)
都带来了相同的值,但select语句仍然没有获取任何记录,都返回9
我已经像这个一样检查过了
select pkid
from AttendancePosting
where datename(dw,AttDate) = 'Sunday' and empid=4 and attdate='2015-12-13'
group by PKId,timeout
having 9=9
它带来了记录,任何帮助都将不胜感激。
首先,您的语句datepart(minute, timeout)/2
将返回一个整数。通过像datepart(minute, timeout)/2.
这样更加精确,可以使SQL Server变得更加精确。
其次,浮点数是一种近似值。您最好使用ROUND()
,并指定您认为合适的小数位数。例如:round(sum((datepart(minute, timeout)))/2.0, 3)
。