我一直在抨击我的头一阵子,所以现在我在这里:)我是一个SQL初学者,所以也许这对你们来说很容易...MySQL:如果行不存在,则返回0
我有这个疑问:
SELECT COUNT(*) AS counter, recur,subscribe_date
FROM paypal_subscriptions
WHERE recur='monthly' and subscribe_date > "2010-07-16" and subscribe_date < "2010-07-23"
GROUP BY subscribe_date
ORDER BY subscribe_date
现在我上面显示的日期是硬编码,我的应用程序将提供一个可变的日期范围。
现在我得到一个结果表,其中有一个值的日期。
counter |recur | subscribe_date
2 | Monthly | 2010-07-18
3 | Monthly | 2010-07-19
4 | Monthly | 2010-07-20
6 | Monthly | 2010-07-22
如果日期不存在,我想返回柜台列。
counter |recur | subscribe_date
0 | Monthly | 2010-07-16
0 | Monthly | 2010-07-17
2 | Monthly | 2010-07-18
3 | Monthly | 2010-07-19
4 | Monthly | 2010-07-20
0 | Monthly | 2010-07-21
6 | Monthly | 2010-07-22
0 | Monthly | 2010-07-23
这可能吗?
是不是像你想的那么简单,但看看这样的答案: http://stackoverflow.com/questions/373490/insert-dates-in-the-return-from-a-query-where-there-is -none/373734#373734 它是同样的问题 – 2010-08-01 11:04:04