我有一个小问题,我的生活在顶部计数错误,但在 while fetch 数组的底部它们都是正确的。
它们存储在数据库中,如下所示
生活 = 1 IPP =1 葬礼 =1
查询应检查该行是否与 1 匹配并对其进行计数。
mysql_query("SELECT DISTINCT consultant, COUNT(*) as total,
sum(CASE WHEN life = '1' then 1 else 0 end) life,
sum(CASE WHEN funeral = '1' then 1 else 0 end) funeral,
sum(CASE WHEN IPP = '1' then 1 else 0 end) IPP
FROM new WHERE call_date = '".$date."' and `qc_status` != 'Fail' GROUP BY consultant ORDER BY total DESC, life DESC, funeral DESC");
我有一个工作人员,他的生命总数是 9 但是当我在它上面运行脚本时 = 8
当我进一步查看列表时,我在 4 上有一名工作人员,在 DB 中是 4。
Full script.
{
$totallife=0;
$totalfuneral;
$totalIPP;
$total =0;
$agents = mysql_query("SELECT DISTINCT consultant, COUNT(*) as total,
sum(CASE WHEN life = '' then 0 else 1 end) as life,
sum(CASE WHEN funeral = '1' then 1 else 0 end) as funeral,
sum(CASE WHEN IPP = '1' then 1 else 0 end) IPP
FROM new WHERE call_date = '".$date."' and `qc_status` != 'Fail' GROUP BY consultant ORDER BY total DESC, life DESC, funeral DESC");
while($agent = mysql_fetch_array($agents)){
$totallife = $totallife+$agent[life];
$totalfuneral = $totalfuneral+$agent[funeral];
$totalIPP = $totalIPP+$agent[IPP];
$total= $total+$agent[total];
echo "<tr><td>".$agent[consultant]."</td><td>".$agent[life]."</td><td>".$agent[funeral]."</td><td>".$agent[IPP]."</td><td>".$agent[total]."</td></tr>";
}
echo "<tr><td><b>TOTALS</b></td><td><b>".$totallife."</b></td><td><b>".$totalfuneral."</b></td><td><b>".$totalIPP."</b></td><td><b>".$total."</b></td></tr>";
}