我遇到了一些mysql查询问题。 我正在尝试将多个表连接在一起。 在一个表中,我有一个成功的在线客户列表,在另一个表中,我有一个表,其中包含来自它的流量来源。我正在尝试跟踪哪些客户来自某个广告。因此,我想查询某个特定日期和特定广告系列中的新客户。
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 :(得分: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 ... JOIN ... WHERE ... GROUP BY .. HAVING .. ORDER BY .. LIMIT
答案 1 :(得分:2)
所有INNER JOIN
条款都必须在FROM
和WHERE
条款之间。在同一查询中使用INNER JOIN
之后的WHERE
语法无效。
正如波希米亚人指出的那样,你也有一个语法错误:Innner
应该是INNER
(你有一个到多个n
个字符。)