2013-01-22 68 views
0
CREATE VIEW tcs.meter_data_eb2 AS 
select ar.created_date AS created_date, 
p.id AS parameter_id, 
p.parameter_name AS parameter_name, 
ar.parameter_value AS parameter_value, 
m.meter_primary_id AS meter_id, 
m.meter_name AS meter_name 
m.meter_code As meter_code 
from tcs.parameter_values_archieve ar 
inner join tcs.parameter_master p on p.id = ar.parameter_id 
inner join tcs.meter_primary_master m on m.meter_primary_id = ar.meter_id 
inner join tcs.meter_master mm on mm.meter_primary_id = m.meter_primary_id; 

此查詢有什麼問題?使用連接創建視圖

它給錯誤:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'm.meter_code As meter_code from tcs.parameter_values_archieve ar inner join tc' at line 8

+0

的,什麼是錯誤消息 –

+0

它的錯誤給你? –

+1

@jw錯誤消息....「您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在'm.meter_code'附近使用正確的語法作爲來自tcs.parameter_values_archieve ar的內部連接tc的meter_code '在第8行「 – user1896796

回答

2

你只是缺乏m.meter_namem.meter_code

, m.meter_name AS meter_name, m.meter_code AS meter_code 

完全視圖查詢之間的逗號,

CREATE VIEW tcs.meter_data_eb2 
AS 
SELECT ar.created_date AS created_date , 
     p.id AS parameter_id , 
     p.parameter_name AS parameter_name , 
     ar.parameter_value AS parameter_value , 
     m.meter_primary_id AS meter_id , 
     m.meter_name AS meter_name, 
     m.meter_code AS meter_code 
FROM tcs.parameter_values_archieve ar 
     INNER JOIN tcs.parameter_master p 
      ON p.id = ar.parameter_id 
     INNER JOIN tcs.meter_primary_master m 
      ON m.meter_primary_id = ar.meter_id 
     INNER JOIN tcs.meter_master mm 
      ON mm.meter_primary_id = m.meter_primary_id;