flask sqlalchement按周查詢數(shù)據(jù)庫數(shù)據(jù)
from datetime import timedelta
from datetime import datetime
c = datetime.datetime(2019, 1, 1, 2, 27, 15, 706351)
int(c.strftime('%W')) # 0, 2019年第0周
c.weekday() # 1, 周2,周一為0
## 數(shù)據(jù)庫查詢第幾年第幾周數(shù)據(jù)
a = Leak.query.filter(extract('week', Leak.create_time)==10, extract('year', Leak.create_time)==2019).all()
from sqlalchemy import func
Leak.query.with_entities(
func.count(Leak.id),
extract('year', Leak.create_time),
extract('week', Leak.create_time)
).group_by(
extract('year', Leak.create_time),
extract('week', Leak.create_time)
).order_by(
extract('year', Leak.create_time)
).order_by(
extract('week', Leak.create_time)
).all()
網(wǎng)站欄目:flasksqlalchement按周查詢數(shù)據(jù)庫數(shù)據(jù)
標題URL:
http://m.br277.com/article/piiogd.html