在按名称列分组时,我在解决如何为每列创建SUM总计时遇到问题。我尝试了几种不同的方法,但一直陷入困境。我知道我必须使用SELECT SUM(),但每次尝试我都会收到错误消息,最感谢任何帮助。
$stats_1013 = mysql_query("SELECT * FROM `refunds_reports`.`stats_1013` WHERE `date` $thedate");
while($stat = mysql_fetch_array($stats_1013)){
if($stat['Name'] =="ULTRA TEST 01"){ } else {
?>
<tr<?php if($alt_row){ $alt_row = 0; echo ' class="alt-row"'; } else { $alt_row = 1; } ?>>
<td><?php echo $stat['Name']; ?></td>
<td><?php echo $stat['Connected']; ?></td>
<td><?php echo $stat['Total Call Duration (sec)']; ?></td>
<td><?php echo $stat['Average Call Duration (sec)']; ?></td>
<td><?php echo $stat['Contact Rate %']; ?></td>
<td><?php echo $stat['Dials']; ?></td>
<td><?php echo $stat['Avg Dial Duration (sec)']; ?></td>
<td><?php echo $stat['No Answer']; ?></td>
<td><?php echo $stat['Busy']; ?></td>
<td><?php echo $stat['Failed']; ?></td>
<td><?php echo $stat['Abandoned %']; ?></td>
<td><?php echo $stat['Dialler Abandoned']; ?></td>
<td><?php echo $stat['User Transfer Attempts']; ?></td>
<td><?php echo $stat['User Transfer Connected']; ?></td>
<td><?php echo $stat['User Transfer Merged']; ?></td>
<td><?php echo $stat['Bad Data']; ?></td>
<td><?php echo $stat['Completed Record']; ?></td>
<td><?php echo $stat['DMC']; ?></td>
<td><?php echo $stat['Recycled Record']; ?></td>
<td><?php echo $stat['Sale']; ?></td>
<td><?php echo $stat['Timed Callback']; ?></td>
<td><?php echo $stat['Answer Machine']; ?></td>
</tr>
答案 0 :(得分:0)
对,我使用正确的mysql
进行了解决 $stats_1013 = mysql_query("SELECT `Name`, COALESCE(SUM(`Connected`),0) AS `ConnectedRow`, COALESCE(SUM(`Total Call Duration (sec)`),0) AS `Total Call Duration (sec)Row`, COALESCE(TRUNCATE(AVG(`Average Call Duration (sec)`),2)) AS `Average Call Duration (sec)Row`, COALESCE(TRUNCATE(AVG(`Contact Rate %`),2)) AS `Contact Rate %Row`, COALESCE(SUM(`Dials`),0) AS `DialsRow`, COALESCE(TRUNCATE(AVG(`Avg Dial Duration (sec)`),2)) AS `Avg Dial Duration (sec)Row`, COALESCE(SUM(`No Answer`),0) AS `No AnswerRow`, COALESCE(SUM(`Busy`),0) AS `BusyRow`, COALESCE(SUM(`Failed`),0) AS `FailedRow`, COALESCE(TRUNCATE(AVG(`Abandoned %`),2)) AS `Abandoned %Row`, COALESCE(SUM(`Dialler Abandoned`),0) AS `Dialler AbandonedRow`, COALESCE(SUM(`User Transfer Attempts`),0) AS `User Transfer AttemptsRow`, COALESCE(SUM(`User Transfer Connected`),0) AS `User Transfer ConnectedRow`, COALESCE(SUM(`User Transfer Merged`),0) AS `User Transfer MergedRow`, COALESCE(SUM(`Bad Data`),0) AS `Bad DataRow`, COALESCE(SUM(`Completed Record`),0) AS `Completed RecordRow`, COALESCE(SUM(`DMC`),0) AS `DMCRow`, COALESCE(SUM(`Recycled Record`),0) AS `Recycled RecordRow`, COALESCE(SUM(`Sale`),0) AS `SaleRow`, COALESCE(SUM(`Timed Callback`),0) AS `Timed CallbackRow`, COALESCE(SUM(`Answer Machine`),0) AS `Answer MachineRow` FROM `refunds_reports`.`stats_1013` WHERE `date` $thedate GROUP BY `Name`;");
while($stat = mysql_fetch_array($stats_1013)){
if($stat['Name'] =="ULTRA TEST 01"){ } else {
?>
<tr<?php if($alt_row){ $alt_row = 0; echo ' class="alt-row"'; } else { $alt_row = 1; } ?>>
<td><?php echo $stat['Name']; ?></td>
<td><?php echo $stat['ConnectedRow']; ?></td>
<td><?php echo $stat['Total Call Duration (sec)Row']; ?></td>
<td><?php echo $stat['Average Call Duration (sec)Row']; ?></td>
<td><?php echo $stat['Contact Rate %Row']; ?></td>
<td><?php echo $stat['DialsRow']; ?></td>
<td><?php echo $stat['Avg Dial Duration (sec)Row']; ?></td>
<td><?php echo $stat['No AnswerRow']; ?></td>
<td><?php echo $stat['BusyRow']; ?></td>
<td><?php echo $stat['FailedRow']; ?></td>
<td><?php echo $stat['Abandoned %Row']; ?></td>
<td><?php echo $stat['Dialler AbandonedRow']; ?></td>
<td><?php echo $stat['User Transfer AttemptsRow']; ?></td>
<td><?php echo $stat['User Transfer ConnectedRow']; ?></td>
<td><?php echo $stat['User Transfer MergedRow']; ?></td>
<td><?php echo $stat['Bad DataRow']; ?></td>
<td><?php echo $stat['Completed RecordRow']; ?></td>
<td><?php echo $stat['DMCRow']; ?></td>
<td><?php echo $stat['Recycled RecordRow']; ?></td>
<td><?php echo $stat['SaleRow']; ?></td>
<td><?php echo $stat['Timed CallbackRow']; ?></td>
<td><?php echo $stat['Answer MachineRow']; ?></td>
</tr>