5

假设我有

ID       |   Column 1 | Column 2
  2      |      NULL  |     "a"
  3      |      "b"   |    NULL
  4      |       "c"  |     "c"

我想写的是这样的:

 SELECT ID FROM table, AnotherTable 
  WHERE (Table.Column1 = AnotherTable.Column IF Table.Column1 IS NOT NULL 
     OR Table.Column2 = AnotherTable.Column IF Table.Column2 IS NOT NULL)

编辑:我还添加了案例 IF Table.Column1 IS NOT NULL AND Table.Column2 IS NOT NULL THEN CHOOSE Table.Column2 = AnotherTable.Column

4

1 回答 1

10

您可以使用以下COALESCE()功能:

SELECT ID
FROM   table JOIN AnotherTable
               ON AnotherTable.Column = COALESCE(table.Column1, table.Column2)
于 2012-12-21T16:39:55.380 回答