0

当且仅当它们对 sql server 中的所有以下列具有值“Y”时,我才需要选择所有行。

Bike_Racks_Lockers  SHELTERS    Telephone   Lighting    FENCES

        N              N            Y           Y          Y                    
        N              N            N           N          Y                
        N              N            N           N          N                
        Y              Y            Y           Y          Y                
        ?              ?            ?           ?          ?                 
        N              N            N           N          N
4

3 回答 3

2
select * from yourtable where Bike_Racks_Lockers = 'Y' and  SHELTERS = 'Y' and 
Telephone = 'Y' and Lighting = 'Y' and FENCES = 'Y'

编辑:

在这种情况下,请单独进行检查并插入到其他表中。例子:

insert into othertable selct * from yourtable where Bike_Racks_Lockers = 'Y' 

insert into someothertable selct * from yourtable where SHELTER = 'Y' 
于 2012-05-30T15:20:50.120 回答
2

用于子句ColumnName='Y'中的每一列:WHERE

SELECT Bike_Racks_Lockers, SHELTERS, Telephone, Lighting, FENCES
FROM [TableName]
WHERE Bike_Racks_Lockers='Y'
AND SHELTERS='Y'
AND Telephone='Y'
AND Lighting='Y'
AND FENCES='Y'

但是,老实说,我不确定这个结果集的意义是什么?

于 2012-05-30T15:21:31.813 回答
2
SELECT * 
FROM   mytable 
WHERE  Bike_Racks_Lockers = SHELTERS 
       AND Telephone  = Bike_Racks_Lockers
       AND Lighting = Bike_Racks_Lockers 
       AND FENCES = Bike_Racks_Lockers 
       AND Bike_Racks_Lockers = 'Y' 
于 2012-05-30T15:21:36.860 回答