Php 警告:子查询返回的行数超过1行
当我运行此查询时Php 警告:子查询返回的行数超过1行,php,mysql,Php,Mysql,当我运行此查询时 SELECT a.sname,a.date,a.Roll_Number,b.branch, COUNT(DISTINCT a.date) AS totaldays, (SELECT COUNT(a.attendance_status) FROM attendance as a , branch as b
SELECT a.sname,a.date,a.Roll_Number,b.branch,
COUNT(DISTINCT a.date) AS totaldays,
(SELECT COUNT(a.attendance_status)
FROM attendance as a , branch as b
WHERE a.attendance_status='Present' and b.id='".$_GET['id']."' and a.branch=b.branch GROUP BY a.sid )
as present_days
FROM attendance as a , branch as b
WHERE b.id='".$_GET['id']."'
and a.branch=b.branch
GROUP BY a.sname ";
它显示了这个错误
警告:mysqli::query:21000/1242:子查询返回的行数超过1行
请帮助我更正此问题。提前感谢您查看您的查询,您现在似乎不需要子查询,要避免此子查询,您应该避免出现错误
SELECT a.sname
,a.date,a.Roll_Number
,b.branch,
COUNT(DISTINCT a.date) AS totaldays,
COUNT(a.attendance_status) as present_days
FROM attendance as a
INNER JOIN branch as b ON a.attendance_status='Present'
and b.id='".$_GET['id']."'
and a.branch=b.branch
GROUP BY a.sid
不管怎么说,你应该考虑到sqlinjection的风险。。您不应该在sql中使用php var,而应该使用prepared语句和binding参数 其中b.id='.$\u GET['id'].'因为您按分组,所以您的计数可以返回多行。这对于子查询是非法的,它们只能返回一行。我需要正确的查询。因为我是Mysql新手