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 7160649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:26:00+00:00 2026-05-28T13:26:00+00:00

Why the query is not working SELECT (sum(`result` = 1)/count(id) * 100) as `abc`,

  • 0

Why the query is not working

SELECT (sum(`result` = 1)/count(id) * 100) as `abc`,  
case 
  when `abc` > 80 then 'pass'
  when `abc` < 80 then 'fail'
end as `abcd` 
FROM `user_quiz_answers` WHERE `user_quiz_id` = 39

TABLE:

id          int(11)         AUTO_INCREMENT                                  
question_id     int(11)                                             
result      tinyint(1)

ERROR:

#1054 - Unknown column 'abc' in 'field list'

I have managed this but not the above one

SELECT 
case 
  when (sum(`result` = 1)/count(id) * 100) > 80 then 'pass' 
  when (sum(`result` = 1)/count(id) * 100) < 80 then 'fail' 
end as `abcd` 
FROM `user_quiz_answers` WHERE `user_quiz_id` = 39
  • 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-05-28T13:26:01+00:00Added an answer on May 28, 2026 at 1:26 pm

    Because you can’t use column aliases as column names in the same query.
    Something like this would work

    SELECT
      `abc`,
      case 
        when `abc` > 80 then 'pass'
        when `abc` < 80 then 'fail'
      end as `abcd` 
    FROM (
      SELECT (sum(`result` = 1)/count(id) * 100) as `abc`
      FROM `user_quiz_answers` WHERE `user_quiz_id` = 39
    ) AS sq
    

    Other, simpler way to do what you seem to want to do would be:

    SELECT 
      IF((sum(`result` = 1)/count(id) * 100) > 80, 'pass','fail') as `abcd`
    FROM `user_quiz_answers` WHERE `user_quiz_id` = 39
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is this query not working? Select temp.CompanyName from ( SELECT c.CompanyName, o.OrderID, YEAR(o.OrderDate)
Order by descending is not working on LINQ to Entity In the following Query
I have this query working but it is not returning back exactly what I
My LINQ query is not producing the expected output below. Basically, it's the sum
Can LINQ to SQL query using NOT IN ? e.g., SELECT au_lname, state FROM
Please let me know why this query is not working together. They are working
I have the following query and it's not working exactly as i want it
I'm writing a query to do some stuff. But its not working the way
WITH abc AS ( SELECT p_id , t1.amount as amount , SUM(amount) OVER (PARTITION
I have the following MySQL query: SELECT SUM(IF(num_content>3,3,num_content)) FROM ( SELECT DATE(FROM_UNIXTIME(content_timestamp)) as dt,

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.