我有一个包含两列的表(好吧,两列与这个问题有关)- pub_date 和 update_date。 pub_date 总是有一个日期,而 update_date 是空的,除非该行被更新。有什么方法可以使用 SELECT 调用返回 update_date,但如果 update_date 为空则回退到 pub_date?
最佳答案
使用 coalesce
功能
The COALESCE function returns the first of its arguments that is not null. Null is returned only if all arguments are null
select coalesce(update_date,pub_date),update_date,pub_date
from yourtable
关于sql - 如果一列为空,则在 SELECT 上选择不同的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28686868/