0

我正在测试几个表中的最新日期在 oracle 中都相互匹配。我想出的 SQL 看起来像:

select ICEAG.process_month
from (
    select *
    from (
        select process_month
        from TABLE1
        group by process_month
        order by process_month desc
    )
    where rownum <=1
) ICEAG
join (
    select *
    from (
        select process_month
        from TABLETWO
        group by process_month
        order by process_month desc
    )
    where rownum <=1
) GAI on (ICEAG.process_month = GAI.process_month)

这可行,但我需要检查大约 12 个表。我应该继续加入更多的子查询,还是有更好的方法?

4

2 回答 2

2
SELECT COUNT(*) FROM (
(SELECT MAX(process_month) FROM TABLE1)
  UNION
(SELECT MAX(process_month) FROM TABLE2)
  UNION
(SELECT MAX(process_month) FROM TABLE3)
);

当结果大于 1 时,其中一个表的最后一个 process_month 不同。

于 2012-10-10T20:40:18.697 回答
1

如果您只是想匹配输出,您可以使用 intersect。

    select process_month
    from TABLETWO
    group by process_month
    order by process_month desc
    where rownum <=1
INTERSECT
    select process_month
    from TABLE1
    group by process_month
    order by process_month desc
    where rownum <=1
于 2012-10-10T20:41:23.883 回答