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

Oracle/SQL:即使计数为零,如何显示日期和计数?,sql,oracle,date,count,Sql,Oracle,Date,Count,所以,我需要查询一个表并显示每天的计数,即使该计数为零。我尝试了下面这样的方法,但它没有显示计数为零的天数。有人有其他想法吗?使用Oracle,顺便说一句。非常感谢 with the_dates as ( select to_date('080114','MMDDYY') + level - 1 as the_date from dual connect by level <= to_date('011716', 'MMDDYY')

所以,我需要查询一个表并显示每天的计数,即使该计数为零。我尝试了下面这样的方法,但它没有显示计数为零的天数。有人有其他想法吗?使用Oracle,顺便说一句。非常感谢

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);
问题是where子句将左连接变为内部连接。因此:

另外,在使用group by时几乎不需要select distinct,在本例中肯定不需要。问题是where子句将左连接变成了内部连接。因此:

另外,在使用GROUPBY时几乎不需要select distinct,在这种情况下当然不需要

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);