如何使用mysql在count函数内编写select查询

时间:2017-12-15 11:08:28

标签: mysql

我有3个查询,实际上计算行数 如下:

 select  count(*) from mydb.ISEVAENQUIRY where dated=15/12/2017 group by dated;

select  count(*) from mydb.ISEVAENQUIRY where dated=15/12/2017 and interested='yes' group by dated

select  count(*) from mydb.ISEVAENQUIRY where dated=15/12/2017 and closed='yes' group by dated;

我想解雇three queries at time如何做到这一点?

如何在一个查询中组合它们?请帮帮我。

2 个答案:

答案 0 :(得分:1)

仅限Mysql,您可以使用以下内容来计算

select  sum(dated='15/12/2017') total,
sum(dated='15/12/2017' and interested='yes') total_interested,
sum(dated='15/12/2017' and closed='yes') total_closed
from mydb.ISEVAENQUIRY 
group by dated;

sum与表达式一起使用时,它将产生一个布尔值0/1,这样你就可以获得条件计数

答案 1 :(得分:-1)

在mySQL手册中查看' UNION'并且' UNION ALL',应该做的伎俩;) https://dev.mysql.com/doc/refman/5.7/en/union.html