选择列值相同的列

问题描述 投票:-1回答:2

这是我的表格数据。

column_1_____column_3_____column_4_____column_5_____column_6_____column_7_____column_8 
   yes         no           yes           yes          yes          no           yes   

这里,它们只是一个数据行

我只想要具有value = 'yes'的列。

为此查询有效吗?

mysql sql
2个回答
2
投票

SQL不是围绕列组织的。它围绕行组织。您可以使用以下查询来执行所需的操作:

select 'column1' as col
from t
where column1 = 'yes'
union all
select 'column2' as col
from t
where column2 = 'yes'
union all
. . .
union all
select 'column8' as col
from t
where column8 = 'yes';

1
投票

您的想法不适合sql逻辑。因为您想了解一些信息,所以查询尚未生效。

© www.soinside.com 2019 - 2024. All rights reserved.