暂无图片
PostgreSQL 子查询字段: SELECT name,(select cn from city where id=s.id) as icn from scenic as s 如果子查询没有值,则icn显示为Null,如何不显示为Null?
我来答
分享
暂无图片 匿名用户
PostgreSQL 子查询字段: SELECT name,(select cn from city where id=s.id) as icn from scenic as s 如果子查询没有值,则icn显示为Null,如何不显示为Null?

PostgreSQL 子查询字段: SELECT name,(select cn from city where id=s.id) as icn from scenic as s 如果子查询没有值,则icn显示为Null,如何不显示为Null?

我来答
添加附件
收藏
分享
问题补充
2条回答
默认
最新
刘贵宾

COALESCE了解一下,coalesce(a,b),a为空显示b,a不为空显示a

SELECT name,COALESCE((select cn from city where id=s.id),'Null') as icn from scenic as s;--子查询为空时显示null

SELECT name,COALESCE((select cn from city where id=s.id),'1234') as icn from scenic as s;--子查询为空时显示1234

SELECT name,COALESCE((select cn from city where id=s.id),'1234') as icn from scenic as s;--子查询不为空时显示cn值


暂无图片 评论
暂无图片 有用 0
暂无图片
DarkAthena
SELECT name, coalesce((select cn from city where id=s.id),'') as icn from scenic as s
暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏