从这样的表中:
id name alias
0 John Null
1 Null Paul
2 Null George
3 Ringo Null
4 Pete Pete
如何选择之间的第一个非空值name
and alias
列,并将其放入自己的列中results
字段,因此输出将是:
id result
0 John
1 Paul
2 George
3 Ringo
4 Pete
你基本上是在描述COALESCE
功能:
https://www.postgresql.org/docs/9.6/static/functions-conditional.html https://www.postgresql.org/docs/9.6/static/functions-conditional.html
在你的情况下:
SELECT id, COALESCE(name, alias) AS result FROM yourtable;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)