2011-07-30 198 views
0

我有一個具有payment_date行的MySQL表。 我從日期X和日期Y得到的行。 我想打印每個日期的出現次數。MySQL的日期範圍:在同一日期之間的出現

例如:

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) 

[不知道!!!!]

任何幫助,請?

回答

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 
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 
0

我會使用類似下面的查詢(假設PAYMENT_DATE是一個日期) :

Select payment_date, count(*) as paymentcount from table_pay where payment_date between 'startdate' and 'enddate' group by payment_date