如何从两个不同的列中选择具有相同值的一行

时间:2020-03-02 21:44:28

标签: sql postgresql select

enter image description here

嗨,我只需要为该表选择一行

第1行= revserse(第4行)

我的代码:

    select ROW_NUMBER() OVER() ID, c.localidad, acalle,bcalle
    from (
      SELECT a.localidad, a.calle acalle, b.calle bcalle
      FROM (
        SELECT LOCALIDAD, CALLE 
        FROM TEST.INICIAL
        WHERE CALLE IS NOT NULL
        GROUP BY 1,2
      ) A
      INNER JOIN (
        SELECT LOCALIDAD, CALLE 
        FROM TEST.INICIAL
        WHERE CALLE IS NOT NULL
        GROUP BY 1,2
      ) B ON A.LOCALIDAD = B.LOCALIDAD 
      WHERE SIMILARITY(A.CALLE ,B.CALLE) > 0.45
         AND A.CALLE <> B.CALLE
    ) c
    where acalle not like '%NORTE' 
      and acalle not like '%SUR' 
      and acalle not like '%ESTE' 
      and acalle not like '%OESTE' 
      AND Bcalle not like '%NORTE' 
      and Bcalle not like '%SUR' 
      and Bcalle not like '%ESTE' 
      and Bcalle not like '%OESTE' 
      AND ACALLE NOT LIKE 'PJE%' 
      AND BCALLE NOT LIKE 'PJE%'
      and acalle not like '%BIS'
      and bcalle not like '%BIS' 
      and acalle not like '%CALLE%' 
      AND BCALLE NOT LIKE '%CALLE%'
    order by 1,2,3

1 个答案:

答案 0 :(得分:1)

使用CASE来确保列值的顺序相同(无论顺序如何,只要从一行到下一行是一致的),就构建一个{{ 1}},然后是[col1, col2]

SELECT DISTINCT
相关问题