问题:使用sqlalchemy如何按月统计数据
解决:使用原生sql语句,使用sqlalchemy的execute方法
方法:
sks_months = self.db.execute("select month(end_time) as month
, sum(used_time) as used_time from student_kejian_stats where
student_id = %d and end_time > %s group by month" % (cuid, year))
.fetchall()
select DATE_FORMAT(create_time,'%Y%m%d') days,count(caseid) count from tc_case group by days;
select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks;
select DATE_FORMAT(create_time,'%Y%m') months,count(caseid) count from tc_case group by months;
注:因为使用的是mysql数据库,所以可以使用month方法
参考:
https://segmentfault.com/q/1010000002488768
http://www.cnblogs.com/joeblackzqq/p/4637654.html
http://linkyou.blog.51cto.com/1332494/751980/