我有一个 iOS 游戏的社区驱动数据库。我正在尝试汇总社区收集的数据,它看起来像这样:
+--------+--------+--------------+
| color1 | color2 | result_color |
+--------+--------+--------------+
| red | blue | purple |
| blue | red | purple |
| red | blue | purple |
| yellow | blue | green |
+--------+--------+--------------+
目前,我正在运行以下查询:
select
count(*) as count,
`Mixes`.*
from
`mixes` AS `Mixes`
where
`result_color` = 'purple'
group_by
color1,
color2
order by
`count` desc
产生以下输出:
+-------+--------+--------+--------------+
| count | color1 | color2 | result_color |
+-------+--------+--------+--------------+
| 2 | red | blue | purple |
| 1 | blue | red | purple |
+-------+--------+--------+--------------+
但是,我希望它产生以下输出,因为在混合颜色时,首先混合哪种颜色并不重要:
+-------+--------+--------+--------------+
| count | color1 | color2 | result_color |
+-------+--------+--------+--------------+
| 3 | red | blue | purple |
+-------+--------+--------+--------------+
所以,我的问题是,如何在 2 列上聚合数据,以便当 color1 为红色且 color2 为蓝色时,聚合函数将其视为与 color1 为蓝色且 color2 为红色时相同?
提前致谢!