two where conditions in a mysql query

Posted by Kaartz on Stack Overflow See other posts from Stack Overflow or by Kaartz
Published on 2010-03-29T11:36:58Z Indexed on 2010/03/29 11:43 UTC
Read the original article Hit count: 252

Filed under:

I have a table like below

|date|dom|guid|pid|errors|QA|comm|
|2010-03-22|xxxx.com|jsd3j234j|ab|Yes|xxxxxx|bad|
|2010-03-22|xxxx.com|jsd3j234j|ab|No|xxxxxx||
|2010-03-22|xxxx.com|jsd3j234j|if|Yes|xxxxxx|bad|
|2010-03-22|xxxx.com|jsd3j234j|if|No|xxxxxx||
|2010-03-22|xxxx.com|jsd3j234j|he|Yes|xxxxxx|bad|
|2010-03-22|xxxx.com|jsd3j234j|he|No|xxxxxx||

I want to retrieve the total count of "dom" referred to each "QA" and also I need the count of "errors" detected by the "QA"

SELECT date, count(dom), QA FROM reports WHERE date="2010-03-22" GROUP BY QA

|2010-03-22|2|ab|
|2010-03-22|2|if|
|2010-03-22|2|he|

SELECT date, count(dom), count(errors), QA FROM reports WHERE errors="Yes" GROUP BY QA

|2010-03-22|1|ab|
|2010-03-22|1|if|
|2010-03-22|1|he|

I want to combine the above two queries, is it possible.

If I use the below query, I am not getting the desired result.

SELECT date, count(dom), QA, count(errors) FROM reports WHERE date="2010-03-22" AND errors="Yes" GROUP BY QA

I want the below output

|2010-03-22|2|ab|1|
|2010-03-22|2|if|1|
|2010-03-22|2|he|1|

Please help me.

© Stack Overflow or respective owner

Related posts about mysql