我有一个数据表如下:
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
答案 0 :(得分:3)
我假设您有一个包含各个名称的资源表。在这种情况下,您可以使用以下查询执行所需操作:
select r.name, <other aggregated results>
from t1 join
Resources r
on concat(', ', t1.resources, ', ') like concat(', %', r.name, ', %')
group by r.name
如果您没有资源表,您可能应该这样做。将这些东西存储在逗号分隔的列表中通常是一个坏主意。如果数据没有标准化,并且出现拼写错误,这是一个特别糟糕的主意。