环境
- 单表结构;
- 数据量在三百万条左右;
- php 7.3.4;
- mysql 5.7;
- tp 5.1.37 LTS;
方法
- group分组统计
- distinct统计
实测
group分组统计:
// OD为 order表对象 ,统计单列值总量
// 耗时为 1394 毫秒
$shops = OD::where($where)->group('shops_id')->count('shops_id');
// 结果为: 1642
distinct去重统计:
// OD为 order表对象 ,统计单列值总量
// 耗时为 1143 毫秒
$shops = OD::where($where)->count('DISTINCT shops_id');
// 结果为: 1642
网友评论