create table test
(
a varchar(20),
b varchar(10)
)
insert into test (b) values('b')
insert into test (a,b) values('','b')
insert into test(a,b) values ('a','b')
select case when a is null then b when a='' then b else a end from test
复制代码 ,粘贴,执行,直接可以看到结果
select case when a is null then b when a='' then b else a end from 表 create table test
(
a varchar(20),
b varchar(10)
)
insert into test (b) values('b')
insert into test (a,b) values('','b')
insert into test(a,b) values ('a','b')
select case when a is null then b when a='' then b else a end from test
复制代码 ,粘贴,执行,直接可以看到结果
select case when a is null then b when a='' then b else a end from 表
select case when a is null then b else a end
from 表
不同数据库写法不一样