使用GQL查找列中的最大值

Ama*_*mar 8 google-app-engine gql max google-cloud-datastore

如何使用GQL在GAE数据存储区中的表的特定列中找到最大值?

Dav*_*ill 11

为了最大限度地利用GQL,您可以这样做:

max_x = db.GqlQuery("SELECT * FROM MyModel ORDER BY x DESC").get().x
Run Code Online (Sandbox Code Playgroud)

您可以使用这种语法上更短但同等的方法:

max_x = MyModel.all().order('-x').get().x
Run Code Online (Sandbox Code Playgroud)