简化sql中的多个并集

简化sql中的多个并集,sql,Sql,我试图简单地执行以下联合查询。基本上,我试图从同一个表的不同列中获取所有可能的值,我必须获取不等于no的值,然后在它们来自相应列时用特定文本替换它们 select 'a' from Mytable where a!='no' and id='1' union select 'b' from Mytable where b!='no' and id='1' union select 'c' from Mytable where c!='no' and id='1' 因此,我的表结

我试图简单地执行以下联合查询。基本上,我试图从同一个表的不同列中获取所有可能的值,我必须获取不等于no的值,然后在它们来自相应列时用特定文本替换它们

select 'a' from Mytable where a!='no' and id='1' 
 union
select 'b' from Mytable where b!='no' and id='1'
  union   select 'c' from Mytable where c!='no' and id='1'  
因此,我的表结构将是

id     Acolumn    BColumn    Ccolumn
1        123a       no         345v
所以我的预期结果是 a c


因此,请建议我简化此查询。提前谢谢。

根据您所写的,这可能没问题

当a'no'和id='1'时选择case,然后选择a'
当b'no'和id='1'时,则为'b'
当c'no'和id='1'时,则为'c'
结束
从mytable
其中(一个“否”和一个id=“1”)
或(b'否'和id='1')
或(c'否'和id='1')

请发布一些示例数据和所需结果,以澄清您的需求。另外,它是用于Oracle还是MySQL?将冲突的产品标记替换为通用sql。请加上你实际使用的一个产品标签。显示你的样品数据和预期输出。清楚地在表中指定示例中所有条件的可用记录,以及需要如何转换这些记录。请不要图片,只有文本数据。
select case when a <> 'no' and id = '1' then 'a'
            when b <> 'no' and id = '1' then 'b'
            when c <> 'no' and id = '1' then 'c'
       end
from mytable
where (a <> 'no' and id = '1')
   or (b <> 'no' and id = '1')
   or (c <> 'no' and id = '1')