表:
Date = 20120101, ID = 123456, ParentID = 654321, System1 = 1, System2 = 1
用户可以在System1
、System2
或两者中处于事件状态(1 = true,0 = false)。查询需要输出如下:
System1 System2
1 0 "System1", "All"
0 1 "System2", "All"
1 1 "System1", "System2", "All"
0 0 "All"
我正在尝试使用 case 语句,但无法让它按照我想要的方式输出。
最佳答案
select *,
case when system1 = 1 and system2 = 0 then 'System1, All'
when system1 = 1 and system2 = 1 then 'System1, System2, All'
when system1 = 0 and system2 = 0 then 'All'
when system1 = 0 and system2 = 1 then 'System2, All'
end as output
from your_table
关于SQL Server 2008条件选择输出多个真值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11890647/