PEEWEE 窗口函数fn.SUM的使用-小记

查询统计总量:

SELECT SUM("t1"."nums") AS "total" FROM "step_collect_infos" AS "t1"

使用的peewee的话,使用方法是:

result = StepCollectInfos.select(fn.SUM(StepCollectInfos.nums).alias('total'))

说明,:
结果返回的是一个ModelSelect

示例:

result = StepCollectInfos.select(fn.SUM(StepCollectInfos.nums).alias('total'))
print(result.sql())
print(type(result))
print(result.dicts()[0].get('total'))
for sds in result.dicts():
    print(sds)

结果:

('SELECT SUM("t1"."nums") AS "total" FROM "step_collect_infos" AS "t1"', [])

11633
{'total': 11633}

你可能感兴趣的:(PEEWEE 窗口函数fn.SUM的使用-小记)