SQL中怎么增加一列,且值根据其它字段的情况而不同(case when。。。then。。。else。。。end)

名称表name


由于 id1 和 id2 中存在一定量的空值记录,现在原表基础上添加一列,要求:当 id1 为空 时,记录 id2 的值;当 id2 为空时,记录 id1 的值。请写出满足条件的 SQL。

select * from name;

select id1,id2 from name;

select id1,id2,case when id1 is null then id2 else id1 end as id3 from name;
全部评论

相关推荐

积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务