我使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。