-5

嗨,我有一张名为test的表。它有 7 列id 、 a 、 b 、 c 、 d 、 e 、 f 。所有这些列都包含 1 或 0。现在我想做一个查询,我只能选择那些值为 1 的列。

像这样的东西:

select (condition) from test where id = 5;  

因为我有一个包含 50 列的酒店表,其中 11 列包含代表酒店设施的 1 或 0。我想查询一下酒店的设施。

任何帮助都会很棒。

4

2 回答 2

0

从测试中选择 id, (a*64)+(b*32)+(c*16)+(d*8)+(e*4)+(f*2)+(g*1)

您可以将此数字反转以转换为 7 位二进制代码。

示例:18 = 0010010,1000000 = 64

于 2012-09-17T10:05:17.857 回答
0

使用 sql 你可以选择行,而不是列

如果这是您想要的,您可以像这样构建您的查询

select id, a, b, c, d -- columns to select
from test  -- table
where (a = 1 or b=1 or c = 1 or d = 1) -- these are the conditions
于 2012-09-17T09:43:07.567 回答