当我们需要两个日期中的最大值作为审核日期时的任何替代方案 如何优化它。
SELECT
a.code,a.name,b.token,a.last_updated,b.last_updated,
CASE WHEN a.last_updated >= nvl(b.last_updated, a.last_updated) THEN
a.last_updated ELSE b.last_updated END AS currdate
FROM
table1 a LEFT JOIN table2 b ON (a.code = b.code
AND b.last_updated > '03/10/2018 13:21:37')
WHERE
a.ou_code IN
(SELECT ou_code FROM table1 WHERE last_updated > '03/10/2018 13:21:37')
OR (b.last_updated > '03/10/2018 13:21:37')
ORDER BY currdate
答案 0 :(得分:0)
我认为您的表没有正确的索引。如果可以的话,我会添加:
create index ix1 on table2 (code, last_updated);
create index ix2 on table1 (last_updated);