我有两个查询返回带有计数的服务项目列表。一个是针对整个数据库的,另一个是针对指定时间段的。它们单独工作得很好,但我想将它们优化为一个查询。
这两个查询是:
SELECT service_type, count(service_type) from qba_customers group by service_type order by count(service_type) desc
SELECT service_type, count(service_type) from qba_customers WHERE created_on BETWEEN '2013-01-01' AND '2013-06-30' group by service_type order by count(service_type) desc
我尝试了一些不成功的事情,以下是我最初认为可行的方法:
SELECT service_type, COUNT(service_type) AS full_count, (count(service_type) WHERE created_on BETWEEN '2013-01-01' AND '2013-06-30') AS period_count FROM qba_customers GROUP BY service_type ORDER BY service_type DESC
提前致谢!