SQL联接无需联接关键字即可联接2个具有公共列的表

时间:2018-09-27 22:01:47

标签: sql oracle join

t2我正在尝试不使用join关键字来联接2个表。两个表的数据类型相同,但是顺序不同。我想在两个表中的排名不同时显示两个表(即airport2017和airport2010)的排名,机场信息,否则跳过该行。不使用join关键字怎么办?

t1

3 个答案:

答案 0 :(得分:0)

我真的不确定这是否是您要查找的内容,但这会找到列出具有col_a和col_b列的两个表中的差异的列表:

    WITH
    aset AS
        (SELECT col_a, col_b FROM table_a
         MINUS
         SELECT col_a, col_b FROM table_b),
    bset AS
        (SELECT col_a, col_b FROM table_b
         MINUS
         SELECT col_a, col_b FROM table_a)
SELECT 'A unique records' AS TYPE, a.*
  FROM aset a
UNION ALL
SELECT 'B unique records' AS TYPE, a.*
  FROM bset a

答案 1 :(得分:0)

虽然我不确定为什么要这样做,但是此查询将为您提供所需的信息:

select airport, max(rank2017) as Rank2017, max(Rank2018) as Rank2018 from 
(
    select airport, airportrank as rank2017, 0 as rank2018 from airport2017
    union
    select airport, 0 as rank2017, airportrank as rank2018 from airport2018
) tabs
group by airport

如果只希望排名已更改的那些,请在底部添加:

having max(rank2017)<>max(Rank2018)

答案 2 :(得分:0)

这将在您希望使用join的情况下起作用:

select a.rank,a.airport from t1 a, t2 b
where a.rank=b.rank

谢谢。