且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从一组列中选择非 NULL 值?

更新时间:2022-12-12 11:21:16

select memberID, coalesce(value1, value2, value3, value4, value5)
from myTable

如果存在所有值都可能为空的可能性,您可能希望默认为一个值.

If the possibility exists that all of the values could be null, you may want to default to a value.

select memberID, coalesce(value1, value2, value3, value4, value5, <default>)
from myTable