3
laterecords
-----------
studentid - varchar
latetime - datetime
reason - varchar
我的查詢:
SELECT laterecords.studentid,
laterecords.latetime,
laterecords.reason,
(SELECT Count(laterecords.studentid) FROM laterecords
GROUP BY laterecords.studentid) AS late_count
FROM laterecords
我得到 「MySQL的子查詢返回多行」 的錯誤。
我知道這個查詢使用下面的查詢解決方法:
SELECT laterecords.studentid,
laterecords.latetime,
laterecords.reason
FROM laterecords
然後使用PHP循環,雖然結果並做以下查詢來獲取late_count
和echo出來:
SELECT Count(laterecords.studentid) AS late_count FROM laterecords
但我認爲可能有更好的解決方案?