时间:2021-07-01 10:21:17 帮助过:13人阅读
统计,就是把基本的数据,整合起来。
用到sql的,有group by 功能,count功能,order by功能等等。
sql将收集的数据,进行统计分析。
一般情况下,sql处理后得到的数据,还要通过php的逻辑来进行整理。
以一定的格式,展示到前台。(推荐学习:PHP编程从入门到精通)
一般都是以数组的方式展示,这也是数据结构的概念。
看这张图片,基本想想结构大概为
{上线数,出单总数,核过总数,总人均,总核率,{(坐席人1,工号1,出单数1,发货数1,核单率1),(坐席人2,工号2,出单数2,发货数2,核单率2)}}
如果用php展示成上面的结构的话,就很好处理了。
首先通过sql获取初次处理的数据,
别小看这初次处理的数据,处理的好,会非常的便捷。
SELECT a.user,count(order_id) as subcount,b.passcount,c.full_name from vicidial_order a LEFT JOIN (SELECT user,count(order_id) as passcount from vicidial_order where time > UNIX_TIMESTAMP('2015-11-7') and user_group = 'TeamOne' and verifysta = 'Y' GROUP BY user ) b on a.user = b.user LEFT JOIN vicidial_users c on a.user = c.user where time > UNIX_TIMESTAMP('2015-11-7') and a.user_group = 'TeamOne' GROUP BY a.user ;
sql思路,归类订单表,以user来进行归类。
获取每个人,当天的订单提交总数count()。
还要获取每个人,订单通过审核的总数,通过where筛选。
然后关联查询其他相关数据。
有了这些基本数据,其他的相关数据都能出来了。
通过php来处理获取,其中变量命名要清晰,这样也有利于阅读代码。
$select_sql = "SELECT a.user,count(order_id) as subcount,b.passcount,c.full_name from vicidial_order a LEFT JOIN (SELECT user,count(order_id) as passcount from vicidial_order where time > UNIX_TIMESTAMP('".$today."') and user_group = '".$user_group."' and verifysta = 'Y' GROUP BY user ) b on a.user = b.user LEFT JOIN vicidial_users c on a.user = c.user where time > UNIX_TIMESTAMP('".$today."') and a.user_group = '".$user_group."' GROUP BY a.user "; $rows = mysqli_query( $db_conn, $select_sql ); $row_counts_list = mysqli_num_rows( $rows ); if ( $row_counts_list != 0 ) { $i = 0; while($rs = mysqli_fetch_assoc( $rows )) // mysqli_fetch_assoc 获取键值数据 mysqli_fetch_field 获取一条数据 mysqli_fetch_fields 获取多组数据 mysqli_fetch_row { $outData['list'][$i]['user'] = $rs['user']; $outData['list'][$i]['full_name'] = $rs['full_name']; $outData['list'][$i]['subcount'] = $rs['subcount']; $outData['list'][$i]['passcount'] = $rs['passcount']; $outData['list'][$i]['passrate'] = round(($rs['passcount']/$rs['subcount'])*100)."%"; $outData['all_subcount'] += $rs['subcount']; $outData['all_passcount'] += $rs['passcount']; $i++; } $outData['all_passrate'] = round(($outData['all_passcount']/$outData['all_subcount'])*100)."%"; $outData['online_count'] = $row_counts_list; $outData['average_subcount'] = round($outData['all_subcount']/$outData['online_count'],1); }
以上就是php怎么确保统计的数据正确的详细内容,更多请关注Gxl网其它相关文章!