错误:“字段列表”中的未知列

时间:2011-08-24 19:26:23

标签: mysql sql

我收到一个错误,列ls.amount在字段列表中 我运行以下查询。

任何人都可以帮我诊断问题。

SELECT c.name, ic.keyword, COUNT(ic.keyword), SUM(ls.amount), ls.buyer FROM in_clicks AS ic
       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;
       INNER JOIN leads AS l ON (ic.id = l.in_click_id)
       INNER JOIN lead_status AS ls ON (l.id = ls.lead_id)
WHERE ic.create_date LIKE '%2011-08-19%' AND ic.location NOT LIKE '%Littleton%' AND discriminator LIKE '%AUTO_POST%'
GROUP BY ic.keyword ORDER BY COUNT(ic.keyword) DESC

确切的错误消息是:

Error Code: 1054
Unknown column 'ls.amount' in 'field list'

1 个答案:

答案 0 :(得分:10)

在第4行删除分号(;)。我怀疑在您定义ls别名之前结束了查询。

SELECT c.name,
       ic.keyword,
       COUNT(ic.keyword),
       SUM(ls.amount),
       ls.buyer
FROM   in_clicks AS ic
       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
       INNER JOIN leads AS l
         ON ( ic.id = l.in_click_id )
       INNER JOIN lead_status AS ls
         ON ( l.id = ls.lead_id )
WHERE  ic.create_date LIKE '%2011-08-19%'
       AND ic.location NOT LIKE '%Littleton%'
       AND discriminator LIKE '%AUTO_POST%'
GROUP  BY ic.keyword
ORDER  BY COUNT(ic.keyword) DESC