我需要城市和这个城市的职位空缺数量。城市,简历,空缺 - 表。
这是我写的一个查询,但它不起作用(第二个左连接不起作用)
SELECT c.name city_name,
COUNT(v.id) vac_num, (r.id) res_num
FROM mnk_city c
LEFT JOIN mnk_vacancy
ON v.cityId = c.id
LEFT JOIN mnk_resume
ON c.id = r.cityId
GROUP BY c.name
答案 0 :(得分:4)
SELECT c.name city_name,
COUNT(v.id) vac_num, (r.id) res_num
FROM mnk_city c
LEFT JOIN mnk_vacancy v
ON v.cityId = c.id
LEFT JOIN mnk_resume r
ON c.id = r.cityId
GROUP BY c.name
您缺少表别名。
答案 1 :(得分:4)
似乎你缺少一些表别名 - mnk_vacancy应该跟随v,我可以看到,mnk_resume应该跟r。
SELECT c.name city_name,
COUNT(v.id) vac_num, (r.id) res_num
FROM mnk_city c
LEFT JOIN mnk_vacancy v
ON v.cityId = c.id
LEFT JOIN mnk_resume r
ON c.id = r.cityId
GROUP BY c.name