我有近 18 个选择联合,每个选择包含几乎 10 个相同的条件,只有一个条件不同。请查看下面的 sql 结构。
SELECT count(*) AS count, 'blue' as title
FROM Users
WHERE [a long list of conditions,which are identical] AND eyes='blue'
UNION
SELECT count(*) AS count, 'hazel' as title
FROM Users
WHERE [a long list of conditions,which are identical] AND eyes='hazel'
UNION
SELECT count(*) AS count, 'Black' as title
FROM Users
WHERE [a long list of conditions,which are identical] AND eyes='black'
等等。
检索此类数据的更好方法是什么。有更好的主意吗?
编辑:
很抱歉之前没有提到这一点,这些条件不是基于单个字段“眼睛”,它可以是不同的,例如头发、身高等,因此不能按照建议使用 group by。