用下面的语句可以实现你要的功能:select user.user_id,user_name,name,count(thread.user_id) as zs from user,thread where thread.user_id = user.user_id group by user.user_id,user.user_name,user.name
union
select user.user_id,user_name,name,0 as zs from user,thread where (user.user_id not in (select user_id from thread)) group by user.user_id,user.user_name,user.name
union
select user.user_id,user_name,name,0 as zs from user,thread where (user.user_id not in (select user_id from thread)) group by user.user_id,user.user_name,user.name
select a.userid,a.user_name,a.name,b.num from [user] a,
(select user_id,count(thread_id) num from thread group by user_id) b where a.user_id=b.user_id
select a.USER_ID,a.USER_NAME,a.NAME,
sum(case when b.THREAD_ID is null then 0 else 1)
from user a left join thread b on a.user_id=b.userid
(select user_id ,count(thread_id) num from thread group by user_id) b on a.user_id=b.user_id
(select user_id ,count(thread_id) num from thread group by user_id) b on a.user_id=b.user_id
a left join
(select user_id ,count(thread_id) num from thread group by user_id) b on a.user_id=b.user_id