【问题标题】:Select rows from a table that has one column matching a combination of columns from another table从具有与另一表中的列组合匹配的一列的表中选择行
【发布时间】:2016-10-18 05:30:23
【问题描述】:

我有 Table1 和 Table2。

Table1 有 columnA 和 columnB 以及其他一些。 Table2有C列和其他列。

我想从 Table2 中查询出满足:columnC 的所有行,遵循这种模式:{Table1_columnA}\_{blahblahblah}\_{Table1_columnB}。请注意,columnC 可以有其他值,例如“123_456_789”,它有两个下划线,但不遵循上述模式。

【问题讨论】:

    标签: postgresql


    【解决方案1】:
    SELECT t2.*
    FROM Table2 t2
    INNER JOIN Table1 t1
        ON t2.columnC LIKE '%' || t1.columnA || '\blahblahblah\' || t1.columnB || '%'
    

    【讨论】:

      【解决方案2】:

      类似这样的:

      select *
      from table1 t1
        join table2 t2 on
             t2.columc = concat('{', t1.columna, '}\_{blablablah}\_{', t1.columnb,'}')
      

      【讨论】:

        猜你喜欢
        • 2020-02-03
        • 1970-01-01
        • 1970-01-01
        • 2020-03-04
        • 1970-01-01
        • 1970-01-01
        • 2013-04-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多