我有以下结果集,我正在尝试向下钻取
+----+---------+---------------+---------------------+----------------------+---------------+-----------+------------------+------------------+
| id | auth_id | trusts_number | buy_sell_actions_id | corporate_actions_id | fx_actions_id | submitted | created_at | updated_at |
+----+---------+---------------+---------------------+----------------------+---------------+-----------+------------------+------------------+
| 2 | 6 | N100723 | 2 | NULL | NULL | 0 | 08/05/2015 11:30 | 08/05/2015 15:32 |
| 5 | 6 | N100723 | NULL | NULL | 1 | 0 | 08/05/2015 15:10 | 08/05/2015 15:10 |
| 6 | 6 | N100723 | NULL | NULL | 2 | 1 | 08/05/2015 15:12 | 08/05/2015 15:41 |
+----+---------+---------------+---------------------+----------------------+---------------+-----------+------------------+------------------+
使用查询
生成此结果集SELECT * FROM actions WHERE auth_id = 6 AND trusts_number = 'N100723'
我也想摆脱fx_actions为NULL的任何字段,所以我将查询更改为
SELECT * FROM actions WHERE auth_id = 6 AND trusts_number = 'N100723' AND fx_actions_id != NULL
然而,这会返回一个空结果集。我以前从未在MySQL中使用过“负面”查询参数,所以我不确定它们是否应该采用不同的语法或什么?
非常感谢任何帮助。
答案 0 :(得分:4)
正常比较运算符与NULL
不兼容。 Something = NULL
和Something != NULL
都将返回'unknown',这会导致在结果中省略该行。请改为使用特殊运算符IS NULL
和IS NOT NULL
:
SELECT * FROM actions
WHERE auth_id = 6
AND trusts_number = 'N100723'
AND fx_actions_id IS NOT NULL
答案 1 :(得分:0)
由于null
不是值,因此您应使用IS NOT NULL