我有以下查询:
<?php
$BM = $_POST['BranchManager'];
$AverageScore = ("ROUND(AVG(Score),1)AS 'Avg <br/> Score'");
$AverageAutofails = ("ROUND(AVG(Autofails),1)AS 'Autofails <br/> per Check'");
$CA003 = ( "SELECT COUNT(*) FROM Data_Table WHERE CA003Result = 'No'");
echo SQLResultTable("SELECT BranchManager, COUNT(SalesExec)AS 'Total<br/> Checks', $AverageScore, SUM(Autofails) AS 'Total <br/>AutoFails', $AverageAutofails, $CA003 FROM Data_Table WHERE BranchManager = '$BM'");
?>
如您所见,它累加了问题、分数、平均值等。
我需要做的是计算问题 3 (CA003) 被回答 NO 的次数。这与其他列无关,上面我尝试进行嵌套查询,但有些东西不起作用。如何将其插入其中,而不限制主查询的结果?
干杯!
所以我现在有这个工作:
$BM = $_POST['BranchManager'];
$AverageScore = ("ROUND(AVG(Score),1)AS 'Avg <br/> Score'");
$AverageAutofails = ("ROUND(AVG(Autofails),1)AS 'Autofails <br/> per Check'");
$CA003 = "(SELECT COUNT(*) FROM Data_Table WHERE CA003Result = 'No' AND BranchManager = '$BM') AS 'CA003'";
$CA004 = "(SELECT COUNT(*) FROM Data_Table WHERE CA004Result = 'No' AND BranchManager = '$BM') AS 'CA004'";
$CA006= "(SELECT COUNT(*) FROM Data_Table WHERE CA006Result = 'No' AND BranchManager = '$BM') AS 'CA006'";
$CA010 = "(SELECT COUNT(*) FROM Data_Table WHERE CA010Result = 'No' AND BranchManager = '$BM') AS 'CA010'";
$CA017 = "(SELECT COUNT(*) FROM Data_Table WHERE CA017Result = 'No' AND BranchManager = '$BM') AS 'CA017'";
$CA022 = "(SELECT COUNT(*) FROM Data_Table WHERE CA022Result = 'No' AND BranchManager = '$BM') AS 'CA022'";
$CA027 = "(SELECT COUNT(*) FROM Data_Table WHERE CA027Result = 'No' AND BranchManager = '$BM') AS 'CA027'";
echo SQLResultTable("SELECT BranchManager, COUNT(SalesExec)AS 'Total<br/> Checks', $AverageScore, SUM(Autofails) AS 'Total <br/>AutoFails', $AverageAutofails, $CA003, $CA004, $CA006, $CA010, $CA017, $CA022, $CA027 FROM Data_Table WHERE BranchManager = '$BM'");
?>
完美显示团队(分支)结果。
目前对于下一张表,我有:
echo SQLResultTable("SELECT SalesExec, COUNT(SalesExec)AS 'Total<br/> Checks', $AverageScore, SUM(Autofails) AS 'Total <br/>AutoFails', $AverageAutofails, FROM Data_Table WHERE BranchManager = '$BM' GROUP BY SalesExec");}
它还需要显示每个 CA00 问题的 No Counts。
第一个查询适用于基于 BranchManager 字段的分支总计,但是对于第二个查询,我需要它来计算每行显示的 SalesExec 的每个 CA00 问题的否。
我真的不知道如何更好地解释它对不起!