I have the below query:
<?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'");
?>
As you can see, it adds up Questions, Score, averages etc.
What I need to do is count up how many times Question 3 (CA003) has been answered NO. This is independent of the other columns, Above I’ve tried to do a nested query but something isn’t working. How can I insert this into there, not limiting the results from the Main Query?
Cheers!
So I now have this working:
$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'");
?>
Which Displays the Team (Branchs) results perfectly.
Currently for the next Table I have:
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");}
Which also needs to display the No Counts for each CA00 question.
The first Query works fine for the Branch Totals based on The BranchManager field, however for the 2nd one I need it to just count the No’s for each CA00 question for the SalesExec shown on each line.
I don’t really know how to explain it any better sorry!
You just need to put
()around the sub query. The final query would look something like…EDIT: Based on your comments and edits…
First set of results…
Second result set…