在 SQLAlchemy 中按小时分组? [英] Group by hour in SQLAlchemy?

查看:30
本文介绍了在 SQLAlchemy 中按小时分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SQLAlchemy 中按日期时间列的小时部分对查询结果进行分组?

How do I group query results by the hour part of a datetime column in SQLAlchemy?

推荐答案

如果我没记错的话,您必须先从时间戳中提取小时,然后才能按此分组.

If I remember correctly you must first extract the hour from your timestamp and then you can group by that.

query(extract('hour', timeStamp).label('h')).group_by('h')

这篇关于在 SQLAlchemy 中按小时分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆