gpt4 book ai didi

SQL 'WHERE NOT some condition' 不排除条件

转载 作者:行者123 更新时间:2023-12-03 18:28:06 30 4
gpt4 key购买 nike

WHERE NOT some condition不从我的查询中排除该条件。

代码:

SELECT 
n.timestamp AS tm
FROM
(SELECT timestamp, uid
FROM nodes
UNION ALL
SELECT timestamp, uid FROM ways) n
WHERE
NOT n.uid = '12055' OR NOT n.uid = '2132512';

目前,此查询返回 3579897 行。

引用:

数据集中的所有时间戳:
SELECT n.timestamp as tm
FROM (SELECT timestamp FROM nodes UNION ALL SELECT timestamp FROM ways) n;

返回 3579897 行。

条件的时间戳:
SELECT n.timestamp as tm
FROM (SELECT timestamp, uid FROM nodes UNION ALL SELECT timestamp, uid FROM ways) n
WHERE n.uid='12055' OR n.uid='2132512'

返回 2254097 行。

最佳答案

我想你想要:

WHERE NOT n.uid = '12055' AND NOT n.uid = '2132512';

您的版本将返回所有行 - 一个或其他条件将(几乎)始终为真。好的,它会过滤掉 NULL n.uid 的值.

或者更 Eloquent 地说:
WHERE n.uid NOT IN ('12055', '2132512');

如果 uid是一个数字(我期望),那么你应该去掉单引号:
WHERE n.uid NOT IN (12055, 2132512);

关于SQL 'WHERE NOT some condition' 不排除条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51118311/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com