【发布时间】:2013-02-06 16:58:45
【问题描述】:
我有一个包含以下数据的 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)
我想返回用户和类型的所有组合,但如果特定用户/类型组合的多个示例仅显示不为空的记录强>。
例如上表应返回以下内容
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 的查询,但无法找到一种方法来匹配我正在寻找的结果。
我还研究了分组依据,然后在 PlayerID 上使用 max,但聚合函数会忽略空值。
如何返回唯一的 ID/类型对及其玩家 ID?
--
来自保罗的问题:
ID Type PlayerID
-------- ----------- -------------------
65823 2 187
37950 1 773
37968 1 773
【问题讨论】:
-
您能否包含产生最佳结果的初始查询?
-
嗨,马特,这只是
SELECT * FROM users,在我的示例中,我删除了实际在表中的不相关列。