我的表格中有项目、任务和状态
**TASK** **STATUS**
task1 N/A
task1 N/A
task1 Yes
task1 Yes
task1 No
task2 No
task2 Yes
我正在尝试将每个任务的完成百分比设置为"is"而不是“不适用”。
为了获得任务的总值(value),我使用了这个sql
select tasks, count(*) as count from mytable where status <> 'NA' group by tasks
有没有办法在单个 sql 中获取 Status = Yes 且不等于 N/A 的唯一任务的百分比值?
最佳答案
select tasks, count(*) as count
, count(*) * 100 / (select count(*)
from mytable
where status <> 'NA' and status = 'yes') as percent
from mytable
where status <> 'NA' and status = 'yes'
group by tasks
关于mysql - 获取mysql表中项目的百分比计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42318615/