这条查询语句怎么写呢?

我有2张表分别是teaching_certification和user,我现在需要从两张表中查询出不同机构下相同学历的人数。
teaching_certification:

img


user:

img


我的查询语句是这么写的,但是没有按照我的要求出结果,求赐教:
我的查询语句:

img


执行结果:

img


可以看到结果统计出在''晶晶'这个机构下的大专'有2个,但是从第一张图上可以看出大专是来自两个不同的user_id。
我需要的查询结果是:

img

不能直接在最后添加user_id=6或其它数字!

根据机构和学历进行分组查询,就可以查到每个机构-每种学历的人数

GROUP BY education_background

你先进teaching_certification和user组合起来,然后按照机构进行分组统计不同学历的数量

执行结果是:

img

select m.education_background,n.institutions_name,count(m.id) from 
(select  id,user_id,education_background from teaching_certification ) m 
join
(select id,institutions_name from user)n
on m.user_id=n.id
GROUP BY institutions_name,education_background

如果需要user_id可以采用以下SQL


select Max(m.user_id) as user_id,m.education_background,count(m.id),n.institutions_name from 
(select  id,user_id,education_background from teaching_certification ) m 
join
(select id,institutions_name from user)n
on m.user_id=n.id
GROUP BY institutions_name,education_background

如有帮助,谢谢采纳~