[英]Retrieve data for specific months
MySQL Query is like this MySQL查询是这样的
SELECT MONTHNAME(access_date) as date,
DATE_FORMAT( access_date, '%m/%Y' ) as month_date ,
COUNT( log_id ) as total_count
FROM user_activity_log
WHERE dam_id = (
SELECT dam_id
FROM dam_content_details
WHERE content_type= '$content_type'
)
AND access_date >= last_day(NOW() - INTERVAL ($month) MONTH)
GROUP BY MONTH( access_date )
ORDER BY access_date ASC
i will pass the numbers like 1,2,3.... then its giving value for that month. 我将传递类似1,2,3 .....的数字,然后给出该月的价值。
The problem i faced is it retrieving the data per 30 days,60 days like that. 我面临的问题是它每30天,60天那样检索数据。 I want if i will write $month = '1;
我想如果我写$ month ='1; then it should return the current month data & previous month data starting from day 1.
那么它应该从第1天开始返回当前月份数据和上个月的数据。
My sample output - $month = 2 我的样本输出-$ month = 2
date month_date total_count
--------- ------------ -----------
December 12/2013 4
January 01/2014 1
I want for december it should calculate from 12/01/2013. 我想从12月1日起计算,到12月。 1st December 2013. Any idea how to solve it ?
2013年12月1日。您知道如何解决吗?
You just have to remove =
from >=
. 你只需要删除
=
从>=
。
Try this: 尝试这个:
SELECT MONTHNAME(access_date) as date,
DATE_FORMAT( access_date, '%m/%Y' ) as month_date ,
COUNT( log_id ) as total_count
FROM user_activity_log
WHERE dam_id = (SELECT dam_id FROM dam_content_details WHERE content_type= '$content_type') AND
access_date > LAST_DAY(NOW() - INTERVAL (($month)+1) MONTH)
GROUP BY MONTH( access_date )
ORDER BY access_date ASC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.