Postgresql 选择计数,即使0个postgres

Postgresql 选择计数,即使0个postgres,postgresql,Postgresql,我想数一数超过一个日期的一堆条目。但是,我也希望得到0的结果。但当前查询在我添加filter by date子句后会立即删除所有0结果。您知道如何获取这些0条目吗 select distinct (e.customer_id), count(m.id) as msgs from eng_msgs e join messages m on e.customer_id = m.customer_id where e.customer_id = m.customer_id and m.created_

我想数一数超过一个日期的一堆条目。但是,我也希望得到0的结果。但当前查询在我添加filter by date子句后会立即删除所有0结果。您知道如何获取这些0条目吗

select distinct (e.customer_id), count(m.id) as msgs from eng_msgs e
join messages m on e.customer_id = m.customer_id
where e.customer_id = m.customer_id
and m.created_at > e.created_at -- this line removes 0 results
group by e.customer_id 
您需要外部联接条件:

select e.customer_id, count(m.id) as msgs
from
    eng_msgs e
    left outer join
    messages m on
        e.customer_id = m.customer_id
        and
        m.created_at > e.created_at
group by e.customer_id