2012年6月4日 星期一

mysql 日,週,月 統計

透過使用 date_format 與 group 的技巧來取得, 日期的統計數字, 不過看起來還是有一點缺點的.


 if ('day' == $Period) { $sql = "select `Ranking`,RankingType, date_format(`RankingDate`, '%m/%d') as dt, `RankingDate` from `Ranking` where 1 RankingType order by `RankingDate` DESC,RankingType"; } elseif ('week' == $Period) { $sql = "select `Ranking`,RankingType, date_format(date_add(`RankingDate`,interval 6-date_format(`RankingDate`,'%w') day),'%m/%d') as dt, date_format(`RankingDate`,'%X %V') as dt2, `RankingDate` from `Ranking` where 1 group by dt2 ,RankingType order by `RankingDate` DESC,RankingType"; } elseif ('month' == $Period) { $sql = "select `Ranking`,RankingType, date_format(`RankingDate`,'%Y-%m') as dt, `RankingDate` from `Ranking` where 1 group by dt ,RankingType order by `RankingDate` DESC,RankingType"; }

【下列文章您可能也有興趣】

沒有留言: