我有一个表,其中包含列名“课程”和“状态”,如下所示
Course Status
---------------------------
Math Complete
Math Complete
Math Complete
Science Incomplete
Science Complete
Science Complete
我想对谁给出以下结果的MySQL查询
Course % Status_complete
--------------------------
Math 100%
Science 33.3%
最佳答案
SELECT Course,
SUM(Status = 'Complete') / COUNT(*) * 1.0 AS STATUS_COMPLETE
FROM TableName
GROUP BY Course
SQLFiddle Demo
SQLFiddle Demo (with % symbol and ROUND())
关于mysql - 我的SQL查询找到#状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16687760/