[英]Warning: subquery returns more than 1 row
當我運行此查詢時
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 行
幫我更正這個查詢。 先感謝您
查看您的查詢似乎您不需要present_days的子查詢,並且避免使用此子查詢,您應該避免錯誤..
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,而是使用准備好的語句和綁定參數 ..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.