为什么赢得这个简单的加入工作?

时间:2015-04-17 16:05:06

标签: mysql join inner-join

我正在尝试让内部联接工作,它从两个表中获取区域代码,并将城市名称放在适当的series_id旁边

 CREATE VIEW medical As
 SELECT series_id AS City, FORMAT(AVG(value),2) AS Average_CPI,     SUBSTRING(series_id,5,4) as areacode, cuArea.city_name, cuArea.area_code
FROM CURRENT
WHERE 
(
(
SUBSTRING(series_id,5,4) = 'A311'
AND SUBSTRING(series_id,9,8) = 'SAM'
AND period = 'M13'
)
OR
(
SUBSTRING(series_id,5,4) = 'A316'
AND SUBSTRING(series_id,9,8) = 'SAM'
AND period = 'M13'
)
)
GROUP BY series_id
INNER JOIN cuArea
ON cuArea.area_code = areacode

1 个答案:

答案 0 :(得分:0)

你在错误的位置得到了JOIN。它应该在FROM之后。

CREATE VIEW medical As
 SELECT series_id AS City, FORMAT(AVG(value),2) AS Average_CPI,     SUBSTRING(series_id,5,4) as areacode, cuArea.city_name, cuArea.area_code
FROM CURRENT
INNER JOIN cuArea
ON cuArea.area_code = current.areacode
WHERE 
(
(
SUBSTRING(series_id,5,4) = 'A311'
AND SUBSTRING(series_id,9,8) = 'SAM'
AND period = 'M13'
)
OR
(
SUBSTRING(series_id,5,4) = 'A316'
AND SUBSTRING(series_id,9,8) = 'SAM'
AND period = 'M13'
)
)
GROUP BY series_id