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の代わりに次のステートメントをさまざまな方法で使用しようとしましたが、クエリを実行できません。2つの日付のうち最新のものを使用するためのより良い方法はありますか?
SELECT CASE WHEN auxDate > infoDate
THEN auxDate
ELSE infoDate END AS activityDate
FROM information
LEFT JOIN otherDates
ON typeid = auxtypeid