我是新手使用vtiger crm。我正在使用vtiger 6.0版本。我正在创建API。 Vtiger表:vtiger_leaddetails几乎有7个缺少记录,我在下面运行查询:它需要将近30秒才能给出响应。任何人都可以帮助我如何优化此查询:
SELECT
COUNT(
CASE WHEN (
crm1.`createdtime` BETWEEN '2017-02-02'
AND '2017-03-18'
) THEN 1 END
) AS `'number_of_leads'`,
COUNT(
CASE WHEN (
vtiger_leaddetails.`current_status` = 'Consent Provided'
AND vtiger_leaddetails.`leadactivitystartdate` BETWEEN '2017-02-02'
AND '2017-03-18'
) THEN 1 END
) AS `'number_of_sales'`,
vtiger_leaddetails.`plan_name` AS `'plan_name'`,
plan.`plan_name_short` AS `'plan_name_short'`,
ROUND(
(
(
COUNT(
CASE WHEN (
vtiger_leaddetails.`current_status` = 'Consent Provided'
AND vtiger_leaddetails.`leadactivitystartdate` BETWEEN '2017-02-02'
AND '2017-03-18'
) THEN 1 END
)
) * 100
) / COUNT(vtiger_leaddetails.lead_no),
2
) AS `'ratio_of_conversion'`,
ROUND(
SUM(
CASE WHEN (
vtiger_leaddetails.`current_status` = 'Consent Provided'
AND vtiger_leaddetails.`leadactivitystartdate` BETWEEN '2017-02-02'
AND '2017-03-18'
) THEN vtiger_leaddetails.`plan_price` END
) / 100000,
2
) AS `'revenu_in_lakh'`
FROM
vtiger_leaddetails
INNER JOIN vtiger_crmentity AS `crm1` ON crm1.crmid = vtiger_leaddetails.leadid
INNER JOIN oa_plan_master AS `plan` ON vtiger_leaddetails.`plan_id` = plan.`oasys_plan_id`
INNER JOIN vtiger_users AS `user_tab` ON user_tab.id = crm1.smownerid
INNER JOIN vtiger_campaign ON vtiger_campaign.campaignid = vtiger_leaddetails.campaign_name
INNER JOIN vtiger_crmentity AS `crm2` ON crm2.`crmid` = vtiger_campaign.campaignid
WHERE
vtiger_leaddetails.leadid > 0
AND crm1.`deleted` = '0'
AND crm2.`deleted` = '0'
AND plan.`deleted` = '0'
AND vtiger_leaddetails.converted = 0
AND (
(
crm1.createdtime BETWEEN '2017-02-02'
AND '2017-03-18'
)
OR (
vtiger_leaddetails.`leadactivitystartdate` BETWEEN '2017-02-02'
AND '2017-03-18'
)
)
GROUP BY
vtiger_leaddetails.`plan_id`
先谢谢!!