计算已完成任务的百分比 mysql
calculate the percentage total in completed tasks mysql
我需要在 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
尝试使用条件聚合:
SELECT
type,
100.0 * AVG(completed = 'true') AS completed
FROM yourTable
GROUP BY
type;
我需要在 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
尝试使用条件聚合:
SELECT
type,
100.0 * AVG(completed = 'true') AS completed
FROM yourTable
GROUP BY
type;