一、根据”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查询





相关文章:

  • 2022-12-23
  • 2021-04-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-12-20
  • 2022-12-23
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案