2011-08-22 120 views
-1

我在使用mysql查詢時遇到了一些問題。 我試圖將多個表連接在一起。 在一張表中,我有一個成功的在線客戶列表,而在另一張桌子上,我有一個表格,它具有來自它的流量來源。我試圖追蹤哪些客戶來自某個廣告。所以我想詢問那些來自特定日期和特定活動的新客戶。Mysql錯誤代碼1064

SELECT keyword, COUNT(keyword) FROM in_clicks AS ic WHERE ic.create_date LIKE '%2011-08-19%' GROUP BY ic.keyword ORDER BY COUNT(ic.keyword) DESC 
     INNER JOIN leads AS l ON ls.lead_id = l.id 
     INNER JOIN lead_status AS ls ON ls.lead_id = ls.id 
     INNER JOIN ads AS a ON ic.ad_id = a.id 
     INNER JOIN ad_groups AS ag ON a.ad_group_id = ag.id 
     INNER JOIN campaigns AS c ON ag.campaign_id = c.id; 

我跑了上面的代碼,並得到以下錯誤。

Error Code: 1064 
'INNER JOIN leads AS l ON ls.lead_id = l.id Innner Join lead_status AS ls' at line 2 
+0

錯誤1064:您的SQL語法中有錯誤。 – Johan

+2

你確定*這是你的查詢?你的查詢中不是「Innner」(而不是「nnner」) – Bohemian

回答

4

這應該運行得更好:-)。

SELECT keyword, COUNT(keyword) 
FROM in_clicks AS ic 
     INNER JOIN leads AS l ON ls.lead_id = l.id 
     INNER JOIN lead_status AS ls ON ls.lead_id = ls.id 
     INNER JOIN ads AS a ON ic.ad_id = a.id 
     INNER JOIN ad_groups AS ag ON a.ad_group_id = ag.id 
     INNER JOIN campaigns AS c ON ag.campaign_id = c.id; 
WHERE ic.create_date LIKE '%2011-08-19%' 
GROUP BY ic.keyword 
ORDER BY COUNT(ic.keyword) DESC 

順序是:SELECT ... FROM ...加入... WHERE ... GROUP BY .. HAVING .. ORDER BY ... LIMIT

2

所有INNER JOIN條款需您的FROMWHERE條款之間。在同一個查詢中使用INNER JOIN跟在WHERE之後在語法上無效。

正如波希米亞指出的那樣,你也有一個語法錯誤:Innner應該是INNER(你有一對多n字符)。