【发布时间】:2012-10-25 14:36:57
【问题描述】:
我有一个数据表如下:
t1
____________________________________________________
resources | companyName | Response | Score
David, Matt | companyA | YES | 5
Matt | compqanyB | NO | 8
Kyle, Kyle, David | companyC | YES | 2
如您所见,resources 是一个逗号分隔的字符串。此外,并非resources 的所有成员都必须是唯一的(参见第 3 行)。
我想GROUP BY 任何列表中的每个DISTINCT 成员。所有其他列将被聚合。
预期结果:
query
______________________________________________________________________________
resources | companyName | Response | Score
David | *agregated result* | *agregated result* | *agregated result*
Matt | *agregated result* | *agregated result* | *agregated result*
Kyle | *agregated result* | *agregated result* | *agregated result*
编辑:
另一种可能性:
query
____________________________________________________
resources | companyName | Response | Score
David | companyA | YES | 5
Matt | companyA | YES | 5
Matt | compqanyB | NO | 8
Kyle | companyC | YES | 2
David | companyC | YES | 2
【问题讨论】:
-
我不认为你可以用纯 SQL 做到这一点,但在任何编程语言(php、java 等)中应该不会太难
-
我将其用于报告服务,因此我尝试直接访问数据库。如果没有必要,我宁愿不使用中间人。但如果这不可能,那我想我必须这样做。
-
您可以在 SQL 中执行此操作,但您必须使用游标。这更像是对真实编程语言的 SQL 模仿,所以我宁愿不去那里。
-
最终结果是让每个资源都获得与它们相关联的票证的分数。我编辑了我的 OP,这个新方向可能吗?每个资源都有另一行?
-
我想这真的只是同一个问题,没有
GROUP BY