我对以下查询有疑问;这本身可以正常工作,但它按秒分组,我想截断秒数并按分钟分组。我已经尝试过 date_trunc、extract 等,但我没有任何运气。当引擎是 sqlite 时,extract('minute') 工作正常,但不适用于 postgresql。
谁能指出我正确的方向?
PostgreSQL 版本:x86_64-redhat-linux-gnu 上的 PostgreSQL 8.1.23
Column('id', Integer, primary_key=True),
Column('date', TIMESTAMP),
Column('src', String),
Column('dst', String),
Column('len', String),
Column('sport', String),
Column('dport', String),
Column('method', String),
Column('host', String),
Column('useragent', String),
Column('statusline', String),
Column('location', String),
Column('server', String),
Column('load', String),
now = datetime.datetime.now()
DD = now - datetime.timedelta(minutes=60)
DD = DD.strftime('%Y-%m-%d %H:%M:%S')
query = session.query(HTTP.date,HTTP.statusline, func.count(HTTP.statusline).
label('count')).filter(HTTP.statusline.like('%'+status+'%'), HTTP.date>=(DD)).group_by(HTTP.date, HTTP.statusline).order_by(asc(HTTP.date)).all()