Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:52:53+00:00 2026-06-09T18:52:53+00:00

I have the below query: <?php $BM = $_POST[‘BranchManager’]; $AverageScore = (ROUND(AVG(Score),1)AS ‘Avg <br/>

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:52:54+00:00Added an answer on June 9, 2026 at 6:52 pm

    You just need to put () around the sub query. The final query would look something like…

    SELECT
      BranchManager,
      COUNT(SalesExec)                                             AS 'Total Checks',
      ROUND(AVG(Score),1)                                          AS 'Avg Score',
      SUM(Autofails)                                               AS 'Total AutoFails',
      ROUND(AVG(Autofails),1)                                      AS 'Autofails per Check',
      (SELECT COUNT(*) FROM Data_Table WHERE CA003Result = 'No')   AS 'Total No'
    FROM
      Data_Table
    WHERE
      BranchManager = '$BM'
    GROUP BY
      BranchManager
    

    EDIT: Based on your comments and edits…

    First set of results…

    SELECT
      BranchManager,
      COUNT(SalesExec)                                     AS 'Total Checks',
      ROUND(AVG(Score),1)                                  AS 'Avg Score',
      SUM(Autofails)                                       AS 'Total AutoFails',
      ROUND(AVG(Autofails),1)                              AS 'Autofails per Check',
      SUM(CASE WHEN CA001Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA001 No',
      SUM(CASE WHEN CA002Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA002 No',
      SUM(CASE WHEN CA003Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA003 No',
      SUM(CASE WHEN CA004Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA004 No',
      SUM(CASE WHEN CA005Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA005 No',
      SUM(CASE WHEN CA006Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA006 No'
    FROM
      Data_Table
    WHERE
      BranchManager = '$BM'
    GROUP BY
      BranchManager
    

    Second result set…

    SELECT
      SalesExec,
      COUNT(SalesExec)                                     AS 'Total Checks',
      ROUND(AVG(Score),1)                                  AS 'Avg Score',
      SUM(Autofails)                                       AS 'Total AutoFails',
      ROUND(AVG(Autofails),1)                              AS 'Autofails per Check',
      SUM(CASE WHEN CA001Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA001 No',
      SUM(CASE WHEN CA002Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA002 No',
      SUM(CASE WHEN CA003Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA003 No',
      SUM(CASE WHEN CA004Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA004 No',
      SUM(CASE WHEN CA005Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA005 No',
      SUM(CASE WHEN CA006Result = 'No' THEN 1 ELSE 0 END)  AS 'Total CA006 No'
    FROM
      Data_Table
    WHERE
      BranchManager = '$BM'
    GROUP BY
      SalesExec
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I have below query I am trying to show message 'No SubSource for this
I have the below query in a postgresql database SELECT * FROM accounts where
I'm using Sql-Server, and I have the below query which returns all columns that
I have below a working query that needs to be simplified. The reason is
I have a query below that I use to retrieve the records not updated
We have the query below. Using a LEFT OUTER join takes 9 seconds to
I have the query below that when run it says that 325 rows were
The query below returns rows that have both loginid and ip2 in the bumps
I have an SQL query (below) that essentially takes a student from tbStudents, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.