SQLAlchemy的group_by和order_by的区别

Posted 沧海一粟,何以久远

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQLAlchemy的group_by和order_by的区别相关的知识,希望对你有一定的参考价值。

1、官网解释:
group_by(*criterion)

apply one or more GROUP BY criterion to the query and return the newly resulting Query

功能:去重和排序

2、官网解释:

order_by(*criterion)

apply one or more ORDER BY criterion to the query and return the newly resulting Query

All existing ORDER BY settings can be suppressed by passing None - this will suppress any ORDER BY configured on mappers as well.

Alternatively, an existing ORDER BY setting on the Query object can be entirely cancelled by passing False as the value - use this before calling methods where an ORDER BY is invalid.

功能:只是排序,并不去重

参考:

1、http://docs.sqlalchemy.org/en/rel_0_9/orm/query.html

以上是关于SQLAlchemy的group_by和order_by的区别的主要内容,如果未能解决你的问题,请参考以下文章

四十三:数据库之SQLAlchemy之group_by和having子句

将 SqlAlchemy group_by/func 查询转换为 GraphQL

Python SQLAlchemy --2

在 sqlalchemy 中使用 distinct()/group_by() 获取基于每个“名称”列的最新记录

SqlAlchemy group_by 并返回最大日期

sqlAlchemy 按DateTime字段的年或月进行group_by查询