sqlAlchemy 按DateTime字段的年或月進行group_by查詢

1、根據」create_date「查詢天天的數據sql

  一、查詢2016年5月天天的數據session

  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()spa

  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
 

 

 

 

 

 

2、.net

 

 

 

 

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

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

相關文章
相關標籤/搜索