2014-10-05 82 views
0

我需要城市和空缺的數量,在這個城市的工作。城市,簡歷,空缺 - 表。任何人都可以糾正sql查詢嗎?

下面是一個查詢我寫的,但它不工作(第二LEFT JOIN不工作)

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 

回答

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

您發佈的速度更快,但我還沒有看到它 - 所以爲您效勞;) – daxur 2014-10-05 08:32:06

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 
相關問題