MySQL如何优化此按日期选择查询以使用索引?

时间:2019-03-27 14:51:07

标签: mysql

我有一张桌子,里面有大约100万条记录,有几个键;客户名称和发票日期,这是两个关键。 enter image description here

然后我有一个查询,用于检索和分组数据。当我在查询上运行解释时,似乎没有使用发票日期索引。如何优化它?

enter image description here

以下是查询:

 SELECT 
  business_unit as 'Service Center',
  fixed_customer_name AS 'Customer',
  trade as 'Trade (system)',
  fixed_trade as 'Trade',
  state as 'State',
  Last_day(invoice_date) as 'Month Ending',
  SUM(revenue) AS 'Revenue',
  (SUM(revenue) - SUM(cogs)) AS 'GP',
  COUNT(fixed_customer_name) as 'Ticket Count',
  fixed_job_type AS 'Type'

FROM Invoice_new

WHERE 
  invoice_date >= '2018-01-01'

GROUP BY
  business_unit,
  fixed_customer_name,
  trade,
  fixed_trade,
  state,
  fixed_job_type,
  Last_day(invoice_date)

Order by
  invoice_date,
  fixed_customer_name,
  fixed_trade

0 个答案:

没有答案