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;
发布了916 篇原创文章 · 获赞 1344 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/qq_35456045/article/details/105451452