group-by - Mysql如何提升Group by + Having型子查询的查询速度(千万级别数据)
PHP中文网
PHP中文网 2017-04-17 11:58:26
0
1
688

如题所示。
有一出货记录表 outDetail。表中大约3000W条数据。
字段如 outId, skuId, outDate, outQty等。

现想查出最近三个月没有出货的SKU号。有如下SQL:
select skuId from outDetail group by skuId having max(outDate) < date_sub(curdate(), interval 90 day);

查询速度很慢。请问如何优化?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
伊谢尔伦

1. Table partition, by month. .
I don’t know your business logic. Is one SKU unique in the shipping record table?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!