我有一个看起来像这样的表:
record no firstType secondtype win?
1 X A 1
2 X A 0
3 X B 1
4 Y B 0
5 Y B 1
6 X B 1
7 X B 1
我需要输出的是这个。
firstType secondType winCounts
X [A,B] [A:1,B:3]
Y [B] [B:1]
所以请注意 secondType 下的数组如何告诉他们与 firstType 发生在哪里,而 winCounts 下的数组则告诉每个 secondType 有多少次获胜与每个 firstType 一起出现。
我可以使用 ARRAY_AGG 制作数组,但我迷失了任何可能的方式来制作 winCounts 列。