计算总的百分比完成的任务的MySQL

问题描述 投票:0回答:1

我需要组并获得百分比真正的完成了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
mysql percentage
1个回答
1
投票

尝试使用有条件聚集:

SELECT
    type,
    100.0 * AVG(completed = 'true') AS completed
FROM yourTable
GROUP BY
    type;

Demo

© www.soinside.com 2019 - 2024. All rights reserved.