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?
Just remove your join, it’s redundant:
This condition
holds for any non-null
buildidin the table.Update:
Your original query (with
=operator) meant this: “take all records from the table wherebuildIdequals to a singleDISTINCTvalue ofbuildIdtaken from the same table, split them into several groups according to the value ofbuildIDand calculate the sums of the expressions within each group”.=operator requires a scalar on both sides. InSQL, 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
INoperator, the query meant “take all records from the table wherebuildIdis found anywhere in the list ofbuildId‘s taken from the same table, split them into several groups according to the value ofbuildIDand calculate the sums of the expressions within each group”.Since
buildIdis always found the in the list ofbuildIstaken from the same table, the condition is redundant.