SQL数据库#1242 - 子查询返回多于1行

时间:2015-04-13 15:49:12

标签: database percentage mysql-error-1242

我有错误

  

1242 - 子查询返回超过1行

(SELECT COUNT(*) FROM attendance GROUP BY stu_ID   ) /(SELECT COUNT(if(`attstatus`='P', `attstatus`,NULL)) 
FROM attendance  GROUP BY stu_ID

我如何解决它,任何其他解决方案都可以显示attstatus='P'的百分比?

SELECT stu_ID,stu_name,

GROUP_CONCAT(if(class_no="lec_1", `attstatus`, NULL)) AS 'Lecturer 1',

GROUP_CONCAT(if(class_no="lec_2", `attstatus`, NULL)) AS 'Lecturer 2',

COUNT(if(`attstatus`='P', `attstatus`,NULL)) AS 'total p',

COUNT(if(`attstatus`='A', `attstatus`, NULL)) AS 'total a',

COUNT(*) as dayTotal,
(SELECT COUNT(*) FROM attendance GROUP BY stu_ID   ) /(SELECT COUNT(if(`attstatus`='P', `attstatus`,NULL)) FROM attendance  GROUP BY stu_ID) 



FROM attendance 

WHERE session_ID=1

GROUP BY stu_ID,stu_name;

1 个答案:

答案 0 :(得分:-1)

尝试添加到您的sql: LIMIT 1
它只返回一行