我的数据库中有两个表
members (member_id, firstname, lastname)
members_photos (member_id, photo_id)
基本上我希望能够以这种方式查询数据以显示以下内容
User Number of photos uploaded
George 15
Steven 3
Mark 0
任何帮助?
答案 0 :(得分:3)
select firstname, count(*)
from members
join member_photos using(member_id)
group by firstname
答案 1 :(得分:0)
您需要连接两个表,然后计算行数。
SELECT
[firstname] as [User],
count(*) as [Number of photos uploaded]
FROM
[members] m
INNER JOIN [members_photos] mp
ON m.[member_id] = mp.[member_id]