我想通过以下规则合并 PostgresQL 查询中的两列:
select (column_1 or column_2) as column_3 from my_table
有没有办法实现它?虽然很清楚,但我想更喜欢column_1
value ascolumn_3
但如果是null
,我希望column_2
value as column_3
。
对不起,如果这听起来很幼稚,谢谢!
使用COALESCE()
. 来自手册9.18.2。合并:
COALESCE 函数返回它的第一个不为空的参数。仅当所有参数都为 null 时才返回 Null。
例如:
select coalesce(column_1, column_2) as column_3 from t
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句