【发布时间】:2018-02-15 16:43:07
【问题描述】:
我尝试了“SELECT * FROM property_table where text is not NULL and method is not NULL”,但我缺少 user2 所有条目和 user4 条目。
【问题讨论】:
-
这篇文章没有显示你的研究或努力。此外,这些行不是重复的。
标签: sql sql-server sql-server-2012
我尝试了“SELECT * FROM property_table where text is not NULL and method is not NULL”,但我缺少 user2 所有条目和 user4 条目。
【问题讨论】:
标签: sql sql-server sql-server-2012
一种方法是聚合:
select col1, col2, max(col3), max(col4)
from t
group by col1, col2;
对于您的示例数据,只过滤掉NULL 值会更容易:
select t.*
from t
where col3 is not null;
【讨论】:
理论上NULL 和NULL 不重复。它们无法比较。
去除“逻辑重复”的方法
select *
from Table
where isnull([column3],'') <> isnull([column4],'')
【讨论】:
isnull(),而是更喜欢coalesce()。
coalesce 而不是另一个,因为:ISNULL 返回值始终被认为是不可为空的,而带有非空参数的COALESCE 被认为是空的。所以表达式 ISNULL(NULL, 1) 和 COALESCE(NULL, 1) 虽然等效但具有不同的可空性值。如果您在计算列中使用这些表达式、创建键约束或使标量 UDF 的返回值具有确定性以便可以对其进行索引,这会有所不同