选择非空或空的值不起作用

时间:2015-06-12 16:35:42

标签: sql

我正在运行查询并尝试仅在值为空或空时才选择值。我正在使用value IS NOT NULL and value <> ' '。但是我仍然得到一些空白值。有什么想法吗?

完整查询:

SELECT T0.[U_QUOTE_NUMBER] FROM ORDR T0
WHERE T0.[U_FORECAST_ORDER] = '02' OR T0.[U_FORECAST_ORDER] IS NULL AND
 (T0.[U_QUOTE_NUMBER] IS NOT NULL AND T0.[U_QUOTE_NUMBER] <>' ')

2 个答案:

答案 0 :(得分:1)

您可能希望将前2个条件包含在括号中,否则,无论Matcher m = Pattern.compile("\"display_name\":\"([^\"]*)\",\"game\"").matcher(str); while(m.find()) { System.out.println(m.group(1)) } 的内容如何,​​您都会获得T0.[U_FORECAST_ORDER] = '02'的所有记录。

T0.[U_QUOTE_NUMBER]

现在的方式,查询以这种方式执行,可能不是你想要的:

SELECT T0.[U_QUOTE_NUMBER] FROM ORDR T0
WHERE (T0.[U_FORECAST_ORDER] = '02' OR T0.[U_FORECAST_ORDER] IS NULL) AND
 (T0.[U_QUOTE_NUMBER] IS NOT NULL AND T0.[U_QUOTE_NUMBER] <>' ')

请注意,SELECT T0.[U_QUOTE_NUMBER] FROM ORDR T0 WHERE T0.[U_FORECAST_ORDER] = '02' OR (T0.[U_FORECAST_ORDER] IS NULL AND T0.[U_QUOTE_NUMBER] IS NOT NULL AND T0.[U_QUOTE_NUMBER] <>' ') 的优先级高于AND

答案 1 :(得分:0)

更改:

selection.columns(5)

要:

(T0.[U_QUOTE_NUMBER] IS NOT NULL AND T0.[U_QUOTE_NUMBER] <>' ')