MySQL多表关联查询数量


//多表关联查询数量
select user, t1.count1, t2.count2
from user t
left join (
select user_id, count(sport_type) as count1
from sport group by user_id
) t1
on t.id = t1.user_id
left join (
select user_id, count(level) as count2
from grade group by user_id
) t2
on t.id = t2.user_id
order by t.id

转载于:https://www.cnblogs.com/liruning/p/6526539.html

你可能感兴趣的:(MySQL多表关联查询数量)