我尝试按用户ID计算数据记录,但结果是总行记录,我有下面的数据 enter image description here
我在这里使用查询:
SELECT user.id, COUNT(upload.user_id), upload.file_name FROM upload Right JOIN user ON upload.user_id = user.id;

答案 0 :(得分:0)
如果您想按user_id
计算,那么您根本不需要JOIN
,它可以是一个简单GROUP BY
COUNT
,例如:
SELECT user_id, COUNT(*)
FROM upload
GROUP BY user_id;
答案 1 :(得分:0)
我会这样做SELECT us.id, (select count(*) from upload where user_id=us.id), u.file_name FROM upload u, user us where u.user_id = us.id;