我需要类似的东西...但它显然不起作用,不确定我是否需要使用任何JOIN或什么。非常感谢!感谢。
vicidial_closer_log。user
= vicidial_users。user
= vicidial_campaign_agents。user
SELECT
vicidial_closer_log.call_date,
Count(vicidial_closer_log.`status`) AS call_count,
vicidial_closer_log.`user`,
vicidial_closer_log.user_group,
vicidial_users.`user`,
vicidial_users.full_name,
vicidial_campaign_agents.`user`,
vicidial_campaign_agents.campaign_rank
FROM
vicidial_closer_log ,
vicidial_users ,
vicidial_campaign_agents
WHERE
date_format(vicidial_closer_log.call_date, '%Y-%m-%d') BETWEEN '2014-04-02' AND '2014-04-02' AND
vicidial_closer_log.`user` NOT LIKE 'VDCL' AND
vicidial_closer_log.`status` NOT LIKE 'CS' AND
vicidial_closer_log.`status` NOT LIKE 'NANQUE' AND
vicidial_closer_log.`status` NOT LIKE 'TIMEOT' AND
vicidial_closer_log.user_group IN ('RAD_US', 'RAD_JAM') AND
vicidial_closer_log.`user` = vicidial_users.`user`
GROUP BY
vicidial_closer_log.`user`
ORDER BY
vicidial_closer_log.`user` ASC
答案 0 :(得分:0)
您在WHERE子句上放置[vicidial_closer_log。user
= vicidial_users。user
]的方式并不完全错误,但您忘记链接vicidial_campaign_agents表。如果你添加一个
AND vicidial_users.user = vicidial_campaign_agents.user
在WHERE子句的末尾应该工作,但尝试习惯JOIN子句。这是正确的做法,使您的查询看起来更漂亮。
JOIN子句非常简单,其工作方式如下:table_a JOIN table_b ON table_a.key = table_b.key。 ON子句指定table_a和table_b之间必须匹配的列,然后使用table_c执行相同的操作来加入结果。
就像这样:
SELECT
l.call_date,
Count(l.status) AS call_count,
l.user,
l.user_group,
u.full_name,
a.campaign_rank
FROM
vicidial_closer_log l
JOIN vicidial_users u ON l.user = u.user
JOIN vicidial_campaign_agents a ON u.user = a.user
WHERE
date_format(l.call_date, '%Y-%m-%d') BETWEEN '2014-04-02' AND '2014-04-02' AND
l.user <> 'VDCL' AND
l.status NOT IN ('CS', 'NANQUE', 'TIMEOT') AND
l.user_group IN ('RAD_US', 'RAD_JAM')
GROUP BY
l.user
ORDER BY
l.user ASC
我希望它有效。