我有以下型号:
class Conversation:
questionId = db.IntegerProperty(required=True)
count = db.IntegerProperty(required=True)
message = db.StringProperty(required=True)
对话由原始问题ID,消息计数和消息组成。所以数据的一个例子是:
- questionId: 2; count: 0; message: How are you?
- questionId: 2; count: 1; message: I'm fine thanks, how are your kids?
- questionId: 2; count: 2; message: They're great, growing to fast!
- questionId: 3; count: 0; message: John, your late!
- questionId: 3; count: 1; message: I know, I'm so sorry!
我的问题是,如何查询每个问题ID的最新(最大)计数?从上面的例子中,它将返回:
- questionId: 2; count: 2; message: They're great, growing to fast!
- questionId: 3; count: 1; message: I know, I'm so sorry!
请记住,遗憾的是数据的存储方式与示例中的排序方式不同,因此请想象所有行都不按顺序排列。表数量也很大!非常感谢!
答案 0 :(得分:0)
您有两种选择:
.get()
。哪个最有意义取决于您在任何给定时间检索的唯一问题。如果它不止一些,你应该修改你的模型。
答案 1 :(得分:0)
question_id = 'whatever'
latest_convo = Conversation.gql('WHERE questionId = :1 ORDER BY count DESC', question_id).get()