现在我有一个 sql 查询,它选择我的销售代表范围,然后加入一个客户表,并计算某些值是否为真。但是,我的查询有效,它忽略了未售出任何客户的销售代表。我希望此查询返回所有销售代表,即使他们没有创建任何符合条件的客户记录。我需要改变什么?
这是我的 SQL 查询的链接:http: //pastie.org/4557540(下同)
SELECT u.id AS
`employee_id`,
u.`first_name` AS
`employee_first_name`,
u.`last_name` AS
`employee_last_name`,
(SELECT Count(*)
FROM saleset s
WHERE s.pitchedby_id = `employee_id`
AND s.pitchstartedat BETWEEN '2012-08-20 00:00:00' AND
'2012-08-20 23:59:59') AS
`transfers_taken`,
Count(IF(c.`saletype_id` IS NOT NULL, 1, NULL)) AS
`total_closes`,
Count(IF(c.`saletype_id` = 1, 1, NULL)) AS
`regular_sale`,
Count(IF(c.`saletype_id` = 2, 1, NULL)) AS
`postdated_sale`,
Count(IF(c.`saletype_id` = 4, 1, NULL)) AS
`attempted_sale`,
Count(IF(c.`customerstatus_id` IN ( 8, 18, 23 ), 1, NULL)) AS
`cancel_status`,
Count(IF(c.`customerstatus_id` IN ( 1, 12, 13, 24 ), 1, NULL)) AS
`pending_completion_status`,
Count(IF(c.`customerstatus_id` IN ( 5, 6, 16 ), 1, NULL)) AS
`complete_status`,
Count(IF(c.`customerstatus_id` = 20, 1, NULL)) AS
`postdate_pending`,
Count(IF(c.`customerstatus_id` = 25, 1, NULL)) AS
`postdate_declined`
FROM `user` u
LEFT JOIN customer c
ON c.`salesrep_id` = u.id
WHERE u.id IN ( 39, 65, 76, 96,
195, 266, 349, 401,
402, 404, 405, 407,
411, 412 )
AND c.`activationdate` BETWEEN
'2012-08-20 00:00:00' AND '2012-08-20 23:59:59'
GROUP BY u.`id`