sqlAlchemy 按DateTime字段的年或月进行group_by查询

一、根据”create_date“查询每天的数据

  1、查询2016年5月每天的数据

  session.query(extract('day', User.create_date).label('day'), func.count('*')).filter(extract('month', User.create_date) == 5, extract('year', User.create_date) == 2016).group_by('day').all()

  month_field = extract('month', User.create_date) == month
  year_field = extract('year', User.create_date) == year   between = User.create_date.between("2016-6-5 00:00:00", "2016-6-15 00:00:00")
  counts = session.query(day, func.count('*')).filter(month_field, year_field, between).group_by('day').all()
  end = datetime.now()
  start = datetime.now() + timedelta(days=-int(time_section))
  between = User.create_date.between(start, end) .注意start和end
 

 

二、

---------2016-6-16 12:10:00--

  source:【1】、sqlalchemy按DateTime字段的年或月进行group_by查询



上一篇:Flask-DebugToolbar


下一篇:HTML之jQuery