相关疑难解决方法(0)

为什么NULL = NULL在SQL Server中评估为false

在SQL Server中,如果 nullParam=NULL在where子句中,它总是计算为false.这是违反直觉的,并且给我带来了许多错误.我确实理解IS NULLIS NOT NULL关键字是正确的方法.但是为什么SQL服务器会以这种方式运行?

sql sql-server null

137
推荐指数
10
解决办法
11万
查看次数

113
推荐指数
3
解决办法
11万
查看次数

什么是"= null"和"IS NULL"

"= null"和"IS NULL"有什么区别?他们如何使用不同的方式?

mysql database

31
推荐指数
3
解决办法
1万
查看次数

Postgresql并与空字段进行比较

似乎在PostgreSQL中,empty_field != 1(或其他一些值)是假的.如果这是真的,有人可以告诉我如何与空字段进行比较吗?

我有以下查询,转换为"选择用户组中尚未投票的所有帖子:

SELECT p.id, p.body, p.author_id, p.created_at
FROM posts p
LEFT OUTER JOIN votes v ON v.post_id = p.id
WHERE p.group_id = 1 
AND v.user_id != 1
Run Code Online (Sandbox Code Playgroud)

即使投票表为空,它也不输出任何内容.也许我的查询有问题,而不是上面的逻辑?

编辑:似乎改变v.user_id != 1v.user_id IS DISTINCT FROM 1,完成了这项工作.来自PostgreSQL文档:

对于非空输入,IS DISTINCT FROM与<>运算符相同.但是,当两个输入都为null时,它将返回false,当只有一个输入为null时,它将返回true.

postgresql null select compare

6
推荐指数
1
解决办法
1万
查看次数

SQL Server 中“is not null”和“&lt;&gt; Null”的区别?

你能帮我吗,我需要了解两者之间的区别

select * from table where field <> NULL;
Run Code Online (Sandbox Code Playgroud)

select * from table where field is not NULL;
Run Code Online (Sandbox Code Playgroud)

看看

SELECT COUNT(*) where (1 = null) -- return 0
SELECT COUNT(*) where (1 <> null) -- return 0
SELECT COUNT(*) where (1 is not  null) -- return 1
SELECT COUNT(*) where (null = null) -- return 0
SELECT COUNT(*) where (null <> null) -- return 0
SELECT COUNT(*) where (null is null) -- return 1
SELECT COUNT(*) where (null is …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

5
推荐指数
1
解决办法
6305
查看次数

null不在详尽的列表中

我有一行满1,2,3和null.为什么没有两个返回相同的结果:

select * from foo where foobar not in (1, 2, 3);
select * from foo where foobar is not null;
Run Code Online (Sandbox Code Playgroud)

第一个返回空集,而第二个返回广告.现在我有点困惑:-D在任何地方都有某种"新手SQL中的NULL"文档吗?:-D

(我正在使用Oracle,如果这很重要)

sql oracle null

2
推荐指数
1
解决办法
161
查看次数

NULL在连接中不匹配

我有2张桌子A和B.

表A.

subgroup    |   maingroup   |   
------------------------------------------  
NULL        |   A       |   
NULL        |   A       |   
Top     |   B       |   
Top     |   B       |   
Run Code Online (Sandbox Code Playgroud)

表B.

subgroup
---------------     
top             
NULL    
Run Code Online (Sandbox Code Playgroud)

我正在运行此查询.

select * from a
join b
on a.subgroup=b.subgroup
group by a.subgroup,a.maingroup,b.subgroup
Run Code Online (Sandbox Code Playgroud)

我得到了这个输出

subgroup    |   maingroup   |   subgroup    
------------------------------------------------------- 
Top     |   B       |   Top 
Run Code Online (Sandbox Code Playgroud)

我担心的是为什么NULL不匹配,并给我输出像NULL A Null.

我正在使用MSSQL

sql sql-server join

2
推荐指数
1
解决办法
74
查看次数

为什么"WHERE column = NULL"在SQL Server中抛出错误?

可能重复:
在where子句+ SQL Server中IS NULL vs = NULL

考虑以下代码 - 有人可以向我解释为什么一个查询不会抛出错误?我可以理解为什么它没有返回记录,但是它想要做什么?请记住,colA是一个int.它在2000,2005和2008 r2上的工作原理相同

create table #foo
( colA int )


insert into #foo
(colA)
values
(null)

select * from #foo --returns the one record we just created

select * from #foo where colA = null --does not throw an error and does not return a record! why??
select * from #foo where colA is null --returns the record

drop table #foo
Run Code Online (Sandbox Code Playgroud)

这个表中是否存在可以返回colA = null的记录?

我目前没有任何其他数据库供我试用 - 这是标准还是特定于MSSQL的行为?

sql sql-server sql-server-2005 sql-server-2008

1
推荐指数
1
解决办法
2331
查看次数

column = null不是woking

我解雇了一个查询

SELECT * FROM tblEmp WHERE emp_id = 9737  AND mgr_id = NULL
Run Code Online (Sandbox Code Playgroud)

它没有回报任何价值.直到昨天它才这样做.什么可能改变?我们很多人在同一台服务器上工作,所以有可能有人改变了一些东西.

为了获得结果,我必须解雇

SELECT * FROM tblEmp WHERE emp_id = 9737  AND mgr_id IS NULL
Run Code Online (Sandbox Code Playgroud)

这是给出适当的输出.

由于我正在使用此查询,.Net我担心如果设置重置为上一个时它会中断.会吗?

sql sql-server

0
推荐指数
1
解决办法
58
查看次数