就此而言,我对 SQL/MySQL 和 Stackoverflow 非常陌生,我正在尝试通过iReport(尽管我不必使用iReport)为SugarCRM CE创建一个查询。我需要创建一个报告,显示链接到特定“用户”(员工)的“推荐”、“语音邮件”、“电子邮件”和“Call_ins”的数量。我目前设置的查询有效;但是,它多次运行数据,生成超过 200 页的报告。这是我目前正在使用的代码:
SELECT
( SELECT COUNT(*) FROM `leads` INNER JOIN `leads_cstm` ON `leads`.`id` = `leads_cstm`.`id_c` WHERE (leadtype_c = 'Referral' AND users.`id` = leads.`assigned_user_id`) ),
( SELECT COUNT(*) FROM `leads` INNER JOIN `leads_cstm` ON `leads`.`id` = `leads_cstm`.`id_c` WHERE (leadtype_c = 'VM' AND users.`id` = leads.`assigned_user_id`) ),
( SELECT COUNT(*) FROM `leads` INNER JOIN `leads_cstm` ON `leads`.`id` = `leads_cstm`.`id_c` WHERE (leadtype_c = 'Email' AND users.`id` = leads.`assigned_user_id`) ),
users.`first_name`,users.`last_name`
FROM
`users` users,
`leads` leads
我将不胜感激任何指导!