我需要分组并在MySQL查询中以真实方式完成百分比
id type completed
1 4 true
2 4 false
3 3 false
4 5 true
5 5 true
结果
type completed
4 %50
3 %0
5 %100
答案 0 :(得分:1)
尝试使用条件聚合:
SELECT
type,
100.0 * AVG(completed = 'true') AS completed
FROM yourTable
GROUP BY
type;