SQL Server 2008条件选择输出多个真值

标签 sql sql-server-2008

表:

Date = 20120101, ID = 123456, ParentID = 654321, System1 = 1, System2 = 1

用户可以在System1System2 或两者中处于事件状态(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/

相关文章:

c# - 如何在两个条件的单个查询中获取多个 SUM()

php - 如何轻松存储用户帐户详细信息?

c# - 窗口服务——等待存储过程得到结果

nhibernate - 如何找到与列关联的规则?

sql - 选择不同的行,同时按最大值分组

sql - 插入错误 : no destination for result data

sql - Rails 按关联计数排序

sql - 在 LINQ 查询中将 xml 转换为字符串

c# - SQL Server 2008 + C# + Inno 安装程序

sql-server - 带有嵌套事务的 SQL Try/Catch 逻辑