SQL 数据显示疑难问题
问题如下
[解决办法]
if OBJECT_ID('test')is not nulldrop table testgocreate table test([900类型] varchar(20),[1800类型] varchar(20),[TD类型] varchar(20))goinsert testselect 'BTS-008','BTS-850','ABS-22' union allselect '','BTS-851','ABS-23' union allselect 'KJH-55','LJD-002','' union allselect 'BTS-010','','' union allselect '','BTS-853','' union allselect '','',''gowith tas(select px=ROW_NUMBER()over(order by getdate()),case when [900类型]='' then 1 else 0 end value1,case when [1800类型]='' then 1 else 0 end as value2,case when [TD类型]='' then 1 else 0 end as value3,* from test)select [900类型],[1800类型],[TD类型],case when value1=1 and value2 =1 and value3=1 then '900类型_1800类型_TD类型' when value1=1 and value2=1 and value3=0 then '900类型_1800类型' when value1=1 and value2=0 and value3=1 then '900类型_TD类型' when value1=0 and value2=1 and value3=1 then '1800类型_TD类型' when value1=0 and value2 =0 and value3=1 then 'TD类型单系统' when value1=1 and value2 =0 and value3=0 then '900类型单系统' when value1=0 and value2 =1 and value3=0 then '1800类型单系统' else '无' end as 系统类型from t/*900类型 1800类型 TD类型 系统类型-----------------------------------------BTS-008 BTS-850 ABS-22 无 BTS-851 ABS-23 900类型单系统KJH-55 LJD-002 TD类型单系统BTS-010 1800类型_TD类型 BTS-853 900类型_TD类型 900类型_1800类型_TD类型*/
[解决办法]
select *,系统类型=case when [900类型] <> '' and [1800类型] <> '' and [TD类型]<>'' then '900+1800+TD' when [900类型] <> '' and [1800类型] <> '' then '900+1800' when [900类型] <> '' and [TD类型]<>'' then '900+TD' when [1800类型] <> '' and [TD类型] <>'' then '1800+TD' when [900类型] <> '' then '900单系统' when [1800类型] <> '' then '1800单系统' when [TD类型] <> '' then 'TD单系统' else '无' end from test