我有一个包含以下数据的 Sybase 表(示例):
Users:
ID Type PlayerID
-------- ----------- -------------------
65823 1 (null)
65823 2 187
91817 1 (null)
37950 1 773
37950 1 (null)
37968 1 (null)
37968 1 773
72576 1 (null)
72576 1 (null)
我想返回用户和类型的所有组合,但如果有多个特定用户/类型组合的示例,则只显示不为 null的记录。
例如,上表应返回以下内容
ID Type PlayerID
-------- ----------- -------------------
65823 1 (null) - although this is null the type/id is unique
65823 2 187
91817 1 (null) - this is null but is a unique type/id
37950 1 773
37968 1 773 - this is included and the id/type that has a null player id isn't
72576 1 (null) - this is a unique type/id
到目前为止,我已经研究了使用 group by、have 和 inner joins 的查询,但一直无法找到一种方法来匹配我正在寻找的结果。
我还查看了 group by 之类的东西,然后在 PlayerID 上使用 max,但聚合函数忽略了 null 值。
如何返回带有玩家 ID 的唯一 ID/类型对?
--
保罗的问题:
ID Type PlayerID
-------- ----------- -------------------
65823 2 187
37950 1 773
37968 1 773