即使日期不在表

时间:2018-01-31 18:39:19

标签: mysql date group-by where records

我在MySQL中进行选择并在两个日期之间进行搜索,并按日期对元素进行计数,并且工作正常但是,如果日期没有记录则不会出现,我正在寻找的是这样的:

列日期/计数

  • 2017-01-01 / 1
  • 2017-01-02/2
  • 2107-01-03 / 0 *没有记录的日期
  • 2017-01-04 / 1

我得到了什么

  • 2017-01-01 / 1
  • 2017-01-02/2
  • 2017-01-04 / 1

2017-01-03因为没有记录而无法显示

查询:

SELECT I.FechaInstalacion, count(Case when I.ServicioId = 1 then 1 end) as P
FROM Instalacion I
WHERE I.EmpleadoId = 4 and I.FechaInstalacion>='2018-01-01' and 
I.FechaInstalacion<= '2018-01-31'
group by I.FechaInstalacion

谢谢!

0 个答案:

没有答案