我無法弄清楚如何修改我的查詢以使用information.infoDate和otherDates.auxDate之間的最新日期。SQL Case語句子選擇按子查詢分組
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
我們是否可以得到一些樣本起始數據/所需的結果輸出? DB2的哪個版本/平臺?並且是否存在'反射''from_date'函數,無論您的目標格式是什麼(爲什麼不存儲在日期/時間/時間戳類型中)? – 2013-03-26 19:58:38