加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在group by子句postgresql中将null值返回为’0′

发布时间:2020-12-13 16:04:42 所属栏目:百科 来源:网络整理
导读:我使用count和group by来了解每天有多少订阅者购买: select count(s.email) from subscriptions s,orders o where o.subcription_id=s.id group by s.created_at 结果: created_at count------------------04-04-2011 106-04-2011 207-04-2011 110-04-2011
我使用count和group by来了解每天有多少订阅者购买:

select count(s.email) 
from subscriptions s,orders o 
where o.subcription_id=s.id 
group by s.created_at

结果:

created_at  count
------------------
04-04-2011  1
06-04-2011  2
07-04-2011  1
10-04-2011  5
11-04-2011  9

但是我仍然希望空行返回为’0′.我该怎么做呢?请注意,我必须使用这两个表.

created_at  count
------------------
04-04-2011  1
05-04-2011  0
06-04-2011  2
07-04-2011  1
08-04-2011  0
09-04-2011  0
10-04-2011  5
11-04-2011  9

解决方法

SELECT  s.created_at,COUNT(o.subsription_id)
FROM    subscriptions s
LEFT JOIN
        orders o
ON      o.subcription_id = s.id
GROUP BY
        s.created_at

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读