试图弄清楚为什么我在调用格式中包含(AM / PM)时编写的sql函数的结果总和为0。
SELECT Label, SUM(Diff)
FROM (
select distinct mr.deviceid, TO_CHAR(mr.ReadDate, 'MM/dd/yyyy hh:00 AM') AS Label, (MAX(ComputedReading) - MIN(ComputedReading)) AS Diff
from reading as mr
WHERE mr.ReadDate >= DATEADD(hour, -100, GetDate()) AND mr.ReadDate <= GetDate() and mr.orgunitid = 1
group by mr.deviceid, label
order by label desc
) as ReadData
GROUP BY Label
ORDER BY Label
我注意到的是,当我将标签修改为:
TO_CHAR(mr.ReadDate, 'MM/dd/yyyy')
然后它实际上会为我提供一笔款项。
不太确定为什么添加am和pm会阻止这种情况。
任何想法
computereading是一个int类型 readdate是日期时间类型
答案 0 :(得分:0)
尝试使用TO_CHAR(TRUNC(mr.ReadDate), 'MM/dd/yyyy')
。看来您的意图是在12:00 AM读ReadDate先生,而TRUNC会做到这一点。