桌子:
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
并回显它:
SELECT Count(laterecords.studentid) AS late_count FROM laterecords
但我认为可能有更好的解决方案?