Oracle/SQL:即使count为零,如何显示日期和计数?

Wic*_*ter 0 sql oracle date count

所以,我需要查询一个表并显示每天的计数,即使该计数为零.我尝试过类似下面的内容,但它没有显示计数为零的日期.有没有其他想法?使用Oracle,BTW.非常感谢!!

with the_dates as (
  select to_date('080114','MMDDYY') + level - 1 as the_date
    from dual
 connect by level <= to_date('011716', 'MMDDYY') 
                     - to_date('080114', 'MMDDYY') + 1
         )
select distinct trunc(a.the_date), count(*)
from the_dates a
left outer join TableFoo f on a.the_date = to_date(admit_date, 'MMDDYYYY')
where f.customer_num = 10
group by trunc(a.the_date)
order by trunc(a.the_date);
Run Code Online (Sandbox Code Playgroud)

Gor*_*off 5

问题是你的where条款变成了left join一个inner join.所以:

with . . .
select trunc(a.the_date), count(f.customer_num)
from the_dates a left outer join
     TableFoo f
     on a.the_date = to_date(admit_date, 'MMDDYYYY') and
        f.customer_num = 10
group by trunc(a.the_date)
order by trunc(a.the_date);
Run Code Online (Sandbox Code Playgroud)

此外,select distinct使用时几乎不需要group by(当然也不是在这种情况下).