美文网首页
tp5.1单列数据去重统计

tp5.1单列数据去重统计

作者: 会游泳的木鱼 | 来源:发表于2019-10-10 10:42 被阅读0次

环境

  1. 单表结构;
  2. 数据量在三百万条左右;
  3. php 7.3.4;
  4. mysql 5.7;
  5. 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

相关文章

网友评论

      本文标题:tp5.1单列数据去重统计

      本文链接:https://www.haomeiwen.com/subject/bojopctx.html