How to find least non-null column in one particular row in SQL?

后端 未结 8 990
别跟我提以往
别跟我提以往 2020-12-29 07:36

I am trying to find the lowest number in two columns of a row in the same table, with the caveat that one of the columns may be null in a particular row. If one of the colum

8条回答
  •  再見小時候
    2020-12-29 08:21

    SELECT MIN(LEAST(COALESCE(COL1, COL2), COALESCE(COL2,CO1))) WHERE COL1 IS NOT NULL AND COL2 IS NOT NULL;

提交回复
热议问题