我正在尝试计算销售的发生。
这是我的查询:
SELECT item, COUNT(item) FROM sales_raw
GROUP BY item HAVING (count(item)>=1)
ORDER BY COUNT(item) DESC
此查询在大约 500,000 行的表上大约需要 11 秒。当我进行解释时,我得到:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE sales_raw index NULL vendor_id 767 NULL 397431 Using temporary; Using filesort
为什么这个查询需要这么长时间,我该如何改进?