我有一个包含很少非键属性的表。我想知道如何编写一个查询来查找键列,在这些键列中的任何一行中都可以找到非空值。
例如1:
Key1 Key2 NonKey1 NonKey2
k1 k2 nk1 nk2
k1 k2 null nk2
k1 k2 nk1 null 例如2:
Key1 Key2 NonKey1 NonKey2 NonKey3
k1 k2 null nk2 nk3
k1 k2 nk1 nk2 null期望值:
Key1 Key2 NonKey1 NonKey2
k1 k2 nk1 nk2发布于 2018-02-24 02:04:12
如下所示:
select key1, key2, max(nonkey2), max(nonkey3)
from MyTable
having max(nonkey2) is not null or max(nonkey3) is not null
group by key1, key2(这是SQL Server,但您已经明白了。)
发布于 2018-02-24 02:03:38
您是否只是想为每个非键列获取一个值?
select key1, key2, max(nonkey1), max(nonkey2)
from mytable
group by key1, key2;发布于 2018-02-26 15:05:21
其他方法:
select distinct key1, key2
from MyTable
where nonkey2 is not null and nonkey3 is not nullhttps://stackoverflow.com/questions/48953563
复制相似问题