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
??没太明白 , 这样? ------解决方案--------------------
你是想合并后,还是1列对吧,是这样吗:
--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 ------解决方案--------------------
SELECT *
FROM (select a from tab where num = 0
UNION ALL
select b from tab where num <> 0)a
------解决方案--------------------
select case when num = 0
then a
when num <> 0
then b
end as C
from tab
------解决方案-------------------- select a, b from tab where ( num = 0 or num <> 0 ) ------解决方案-------------------- 搞错了。。。。。