溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

flask sqlalchement按周查詢數(shù)據(jù)庫數(shù)據(jù)

發(fā)布時間:2020-06-27 14:57:10 來源:網(wǎng)絡(luò) 閱讀:278 作者:wx5dcb7577ac572 欄目:編程語言

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()
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI