跨多个列过滤结果

时间:2016-09-23 17:00:51

标签: tsql

我正在运行查询,结果如下所示:

          JOHN   JILL   GARY   JANE   JEFF   MICK 
RED     | NOPE |  OK  |  OK  |  OK  |  OK  |  OK  |
ORANGE  |  OK  |  OK  |  OK  |  OK  |  OK  |  OK  |
YELLOW  |  OK  |  OK  | NOPE |  OK  | NOPE |  OK  |
GREEN   |  OK  |  OK  |  OK  |  OK  |  OK  |  OK  |
BLUE    |  OK  |  OK  |  OK  |  OK  |  OK  |  OK  |
INDIGO  |  OK  | NOPE |  OK  |  OK  |  OK  |  OK  |
VIOLET  |  OK  |  OK  |  OK  |  OK  |  OK  | NOPE |

我想过滤掉所有列都可以的记录。我只想查看一个或多个列包含NOPE结果的结果。

我尝试了很多不同的变体,其中<>那个或那个=我放弃了,我需要帮助。

3 个答案:

答案 0 :(得分:2)

JOHN + JILL + GARY + JANE + JEFF + MICK<> 'okokokokokok'

答案 1 :(得分:1)

假设列的数量是常量,那么where子句在不翻转的情况下查找一切正常的情况应该这样做。

WHERE (NOT ((JOHN = 'OK') AND (JILL = 'OK') AND (GARY = 'OK') AND (JANE = 'OK') AND (JEFF= 'OK') AND (MICK = 'OK')))

答案 2 :(得分:0)

也许WHERE子句看起来像这样:

WHERE JOHN = 'NOPE'
  OR JILL = 'NOPE'
  OR GARY = 'NOPE'
  OR JANE = 'NOPE'
  OR JEFF = 'NOPE'
  OR MICK = 'NOPE'