sqlalchemy日期格式化,date_format按月统计数据

本文共有849个字,关键词:

问题:使用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/
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论