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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:18:59+00:00 2026-05-13T14:18:59+00:00

I am trying a query like this in MYSQL select Sum(case when WindowsXP =

  • 0

I am trying a query like this in MYSQL

select 
Sum(case when WindowsXP = "PASS" then 1 else 0 end) as PASS ,
Sum(case when WindowsVista = "FAIL" then 1 else 0 end) as FAIL 

from OS_Table where BuildID = (select distinct BuildID from OS_Table)
group by BuildID

The error is Subquery returns more than one row. If I use IN instead of = then the query is going on forever ( nearly after 3 minutes it does not stop)

Basically what I am trying to achieve is for each distinct BuildID, give me counts of PASS, FAIL when WindowsXP = “PASS” and WindowsVista = “FAIL”

I have hardly 10 distinct BuildID’s

How do I achieve this?

  • 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-13T14:19:00+00:00Added an answer on May 13, 2026 at 2:19 pm

    Just remove your join, it’s redundant:

    SELECT  buildid,
            SUM(CASE WHEN WindowsXP = 'PASS' THEN 1 ELSE 0 END) as PASS ,
            SUM(CASE WHEN WindowsVista = 'FAIL' THEN 1 ELSE 0 END) as FAIL 
    FROM    OS_Table
    GROUP BY
            buildId
    

    This condition

    WHERE BuildID IN (SELECT DISTINCT BuildID FROM OS_Table)
    

    holds for any non-null buildid in the table.

    Update:

    Your original query (with = operator) meant this: “take all records from the table where buildId equals to a single DISTINCT value of buildId taken from the same table, split them into several groups according to the value of buildID and calculate the sums of the expressions within each group”.

    = operator requires a scalar on both sides. In SQL, a query is considered a scalar if and only if it returns a recordset of one field and at most one record.

    Your subquery returned more that one record, so you original query failed (with quite a descriptive error).

    With IN operator, the query meant “take all records from the table where buildId is found anywhere in the list of buildId‘s taken from the same table, split them into several groups according to the value of buildID and calculate the sums of the expressions within each group”.

    Since buildId is always found the in the list of buildIs taken from the same table, the condition is redundant.

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

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer pros: Speed - every good js framework is speedier each… May 13, 2026 at 11:16 pm
  • Editorial Team
    Editorial Team added an answer If you look at the gawk info file (info gawk),… May 13, 2026 at 11:16 pm
  • Editorial Team
    Editorial Team added an answer Can't you simply put the import statement in the __init__… May 13, 2026 at 11:16 pm

Related Questions

I have a table emp with following structure and data: name dept salary -----
I am trying to parse XML using PHP DOM and then insert this data
I am trying to write a stored procedure in MySQL which will perform a
I am currently trying to optimize a few queries and scripts, and I wonder
I am trying to combine a few SQL queries to reduce the number of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.