我有一个包含“系统”和“颜色代码”字段的表(详细信息)。我想通过 color_code 计算每个系统的项目百分比,每个系统都有一个 SQL 语句。我有这个:
SELECT system, color_code, Count(color_code) AS ColorCount,
Count(color_code)*100 /(select count(*) from Detail) AS ColorPercent
FROM Detail
GROUP BY system, color_code;
“ColorPercent”中的结果是所有记录的结果。我希望“ColorPercent”基于每个“系统”的记录数。
我试过这个(将“GROUP BY system”添加到表达式中),但它不起作用,
SELECT system, color_code, Count(color_code) AS ColorCount,
Count(color_code)*100/(select count(*) from Detail
GROUP BY system) AS ColorPercent
FROM Detail
GROUP BY system, color_code;