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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:06:19+00:00 2026-06-01T05:06:19+00:00

I have a single product table with multiple fields which contain user evaluations of

  • 0

I have a single product table with multiple fields which contain user evaluations of various attributes:

product  | attr_1_eval   | attr_2_eval   | attr_3_eval
ABC      | Correct       | Incorrect     | Null
DEF      | Incorrect     | Null          | Null
XYZ      | Undetermined  | Null          | Incorrect
123      | Null          | Undetermined  | Correct
456      | Incorrect     | Correct       | Correct

I need to write a query which totals up those attribute evaluations across all products (where not null):

evaluation  | correct   | incorrect   | undetermined
attr_1      | 1         | 2           | 1
attr_2      | 1         | 1           | 1
attr_3      | 2         | 1           | 0

This SQL gets me part way there:

SELECT 
SUM(CASE WHEN attr_1_eval = 'Correct' then 1 else 0 END) AS correct,
SUM(CASE WHEN attr_1_eval = 'Incorrect' then 1 else 0 END) AS incorrect,
SUM(CASE WHEN attr_1_eval = 'Undetermined' then 1 else 0 END) AS undetermined,
SUM(CASE WHEN attr_2_eval = 'Correct' then 1 else 0 END) AS correct,
...
FROM product

But it doesn’t group attr_1, attr_2.. by rows with error counts in the columns (as in the desired result set above). I’m using Postgres but help in any flavor of SQL would be most welcome.

  • 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-01T05:06:20+00:00Added an answer on June 1, 2026 at 5:06 am

    Could you do 3 unions?

    SELECT 
      'attr_1' AS evaluation,
      SUM(CASE WHEN attr_1_eval = 'Correct' then 1 else 0 END) AS correct,
      SUM(CASE WHEN attr_1_eval = 'Incorrect' then 1 else 0 END) AS incorrect,
      SUM(CASE WHEN attr_1_eval = 'Undetermined' then 1 else 0 END) AS undetermined
    FROM product
    UNION
    SELECT 
      'attr_2' AS evaluation,
      SUM(CASE WHEN attr_2_eval = 'Correct' then 1 else 0 END) AS correct,
      SUM(CASE WHEN attr_2_eval = 'Incorrect' then 1 else 0 END) AS incorrect,
      SUM(CASE WHEN attr_2_eval = 'Undetermined' then 1 else 0 END) AS undetermined
    FROM product
    UNION
    SELECT 
      'attr_3' AS evaluation,
      SUM(CASE WHEN attr_3_eval = 'Correct' then 1 else 0 END) AS correct,
      SUM(CASE WHEN attr_3_eval = 'Incorrect' then 1 else 0 END) AS incorrect,
      SUM(CASE WHEN attr_3_eval = 'Undetermined' then 1 else 0 END) AS undetermined
    FROM product
    

    It’s not the most elegant/efficient solution probably but it should get what you want

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

Sidebar

Related Questions

I have a PRODUCTS table, and each product can have multiple attributes so I
I have a single entry output from a paradox table which is imported into
We have an issue where on a single instance of our product we receive
I have a single user java program that I would like to have store
I have two mySQL tables as follows: [product] table P_id | Name | Quantity
Say I have an online store wherein each product has a single category (and
I have 2 tables Table 1 Name: filestable Table 1 Fields: id int name
I have an app with 2 models: Product and Photo , each of which
Basically, I will need to combine product data from multiple vendors into a single
I have a table product with colums product_id prodcut_name category_id another table category category_id

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.