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

  • Home
  • SEARCH
  • 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 8442897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:58:00+00:00 2026-06-10T08:58:00+00:00

I have a table, where questions have been answered either pass or fail. I

  • 0

I have a table, where questions have been answered either pass or fail.

I just need an SQL query to find the percentage of Fails for question 1 out of the total number of questions asked.

I’m trying this, but this is coming up with a Syntax error –

$CA001 = "COUNT(CA001Result WHERE CA001Result = "Fail") / COUNT(CA001Result)) From Datable";

As I said, total noob, it’s MYSQL btw.

I no need to isolate the % results for Product, I’ve got this so far, and have tried GROUP by Product but that didn’t work, any ideas?

$CA001 = "( SELECT ROUND(100 *  (SELECT count(CA001Result ) from Data_Table where (CA001Result='Fail' AND Product='$product' AND Area='$Area'))/count(CA001Result),2) from Data_Table) AS 'CA001 %'";

Looking at it again I need to insert a WHERE Product = ‘Product’ somewhere like where I have it below, however don’t quite understand where to put it as the below doesn’t work:

$CA001 = "( SELECT ROUND(100 * (SELECT count(CA001Result ) from Data_Table where (CA001Result='Fail' AND Product='$product' AND Area='$Area'))/count(CA001Result WHERE Product = '$product'),2) from Data_Table) AS 'CA001 %'";

  • 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-10T08:58:02+00:00Added an answer on June 10, 2026 at 8:58 am

    Suppose this is your table:

    ID     Answer
    -------------
     1  ,  'pass'
     2  ,  'pass'
     3  ,  'fail'
     4  ,  'fail'
     5  ,  'fail'
     6 ,   'fail'
    

    So you need to use a subquery like this:

    SELECT 100 * 
    (SELECT COUNT(answer) FROM t WHERE answer='fail')/COUNT(answer)
    AS Fail_percent FROM t;
    

    Or you can use COUNT with CASE like this:

    SELECT 100 * 
    COUNT(CASE WHEN answer = 'fail' THEN 1 ELSE NULL END)/COUNT(answer)
    AS Fail_percent FROM t;
    

    Or you can use SUM with CASE like this:

    SELECT 100 * 
    SUM(CASE WHEN answer = 'fail' THEN 1 ELSE 0 END)/COUNT(answer)
    AS Fail_percent FROM t;
    

    Or you can use SUM without using CASE (Only for MySQL) like this:

    SELECT 100 * 
    SUM(answer = 'fail')/COUNT(answer)
    AS Fail_percent FROM t;
    

    See this SQLFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem in a SQL command. I have a table with questions,
I know this must have been answered before here, but I simply can't find
I've seen similar questions on SO-most of them have not been answered. Those that
I think similar questions have been answered, but none really seem to have helped
I know questions with this title have been answered before, but please do read
it is possible that similar questions have been asked earlier, but I can't find
I have a table with questions, where each row is a question and all
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data
Requirements : I have a table of several thousand questions. Users can view these
I have a MS access database. In that, one table consists of questions 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.