34,590
社区成员
发帖
与我相关
我的任务
分享
select case when num = 0
then a
when num <> 0
then b
end as C
from tab
SELECT *
FROM (select a from tab where num = 0
UNION ALL
select b from tab where num <> 0)a
--drop table tab
create table tab(a int,b int,num int)
insert into tab
select 1,2,100 union all
select 3,4,0
--注意字段a和字段b,是同一种数据类型
select case when num = 0
then a
when num <> 0
then b
else null
end as xx
from tab
/*
xx
2
3
*/
SELECT (CASE WHEN Num = 0 THEN A ELSE NULL END) AS A,
(CASE WHEN Num <> 0 THEN B ELSE NULL END) AS B
FROM Tab
??没太明白 , 这样?