我不知道如何修改我的查询以使用 information.infoDate 和 otherDates.auxDate 之间的最新日期。
SELECT state, COUNT(type) as EQUIPMENT,
(SELECT COUNT(type)
FROM information a
WHERE a.state = b.state
AND storedprocedures.to_date(infoDate) < (SELECT current date - 5 days
FROM sysibm.sysdummy1)
GROUP BY state) as IDLE,
ROUND((SELECT COUNT(type)
FROM information a
WHERE a.state = b.state
AND storedprocedures.to_date(infoDate) < (SELECT current date - 5 days
FROM sysibm.sysdummy1)
GROUP BY state) / CAST(COUNT(type) as float) * 100, 1) as percent
FROM information b
JOIN validStates
ON state = vstate
LEFT JOIN otherDates
ON typeid = auxtypeid
WHERE state <> '***'
GROUP BY state
ORDER BY state
我已经尝试过使用以下语句而不是 infoDate 的各种方式,但我无法运行查询。有没有更好的方法来使用两个日期中的最新日期?
SELECT CASE WHEN auxDate > infoDate
THEN auxDate
ELSE infoDate END AS activityDate
FROM information
LEFT JOIN otherDates
ON typeid = auxtypeid