mysql查询中的两个where条件

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|

#0

You can do this with:

SELECT date, COUNT(dom), QA, COUNT(NULLIF(errors, 'No')) FROM reports WHERE date="2010-03-22" GROUP BY QA

To explain how this works: COUNT returns the number of non-null values. We can use this to our advantage by turning errors with 'No' into NULL, so COUNTwon't count them. We do this with the NULLIF function, which returns NULL if the first and second arguments are equal.

#1

Try using OR in place of AND:

.... date="2010-03-22" OR errors="Yes" GROUP BY QA

推荐文章

java中的包类设计与访问粒度

java中的包类设计与访问粒度

推荐文章

openGLES中的简单2D-UV映射问题

openGLES中的简单2D-UV映射问题

推荐文章

NHibernate映射文件中的hbm代表什么?

NHibernate映射文件中的hbm代表什么?

推荐文章

从ip cam获取快照的最快方法是什么

从ip cam获取快照的最快方法是什么

推荐文章

android listView错误。。。。不应从后台线程设置适配器。。。。!

android listView错误。。。。不应从后台线程设置适配器。。。。!

推荐文章

asp.net验证摘要位置/焦点

asp.net验证摘要位置/焦点

推荐文章

如何禁用默认qpushbutton

如何禁用默认qpushbutton

推荐文章

运行时错误检查/RTCs

运行时错误检查/RTCs

推荐文章

将非类型参数模板化为静态成员函数

将非类型参数模板化为静态成员函数

推荐文章

如何组合两个flot示例(Jquery)

如何组合两个flot示例(Jquery)

推荐文章

PHP DOMDocument获取具有特定属性名的元素数据

PHP DOMDocument获取具有特定属性名的元素数据

推荐文章

检查元素是否存在于C++地图中?

检查元素是否存在于C++地图中?

推荐文章

如何在调整窗口大小时禁用菜单换行和启用水平滚动?

如何在调整窗口大小时禁用菜单换行和启用水平滚动?

推荐文章

PHP Mysql&Jquery动态填充多条记录

PHP Mysql&Jquery动态填充多条记录

推荐文章

Java字符串优化

Java字符串优化

推荐文章

WPF,C#,TaskbarItemInfo:隐藏缩略图窗口?

WPF,C#,TaskbarItemInfo:隐藏缩略图窗口?