我有一个MySQL表,其中有一个payment_date行。 我从日期X和日期Y获取行。 我想打印每个日期的出现次数。
例如:
payment_date
2011-07-25
2011-07-24
2011-07-25
2011-06-13
我需要将其归还:
2011-07-25 got 2 payments
2011-07-24 got 1 payments
2011-06-13 got 1 payment
有了这个信息,我正在做一个情节,X轴:日期和Y轴:付款次数。
我现在的查询是:
SELECT *
FROM table_pay
WHERE DATE_FORMAT(payment_date, '%m/%d/%Y')
BETWEEN '$payment_date_from'
AND
DATE '$payment_date_to'
GROUP BY DATE(payment_date)
[不知道!!!!]
请帮忙吗?
答案 0 :(得分:1)
SELECT
payment_date,count(*) as tot
FROM table_pay
WHERE payment_date
BETWEEN '$payment_date_from'
AND
'$payment_date_to'
GROUP BY payment_date
order by tot desc
答案 1 :(得分:0)
试试这个,现在无法测试,所以请回答它是否按预期工作
SELECT DATE_FORMAT(payment_date, '%Y-%m-%d'), COUNT(*)
FROM table_pay
WHERE payment_date BETWEEN '$payment_date_from' AND '$payment_date_to'
GROUP BY payment_date
答案 2 :(得分:0)
我会使用如下的查询(假设payment_date是日期):
Select payment_date, count(*) as paymentcount from table_pay where payment_date between 'startdate' and 'enddate' group by payment_date