核心数据谓词与组和MAX() [英] Core data predicate with group and MAX()

查看:140
本文介绍了核心数据谓词与组和MAX()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象在核心数据有2个字段:名称和日期。每次一个人签到时,都会保存他们的姓名和他们的时间。

I have an object in core data that has 2 fields: Name and Date. Each time a person checks in it saves their name and the time they did it.

有办法获得所有唯一人员的列表,使用核心数据中的谓词?

Is there a way to get a list of all unique people with their last check in time using a predicate in core data?

注意:我知道两个表会更容易。

Note: i do know that 2 tables would make it easier.

这个sql是

select 
    clientName
    , MAX(ModifiedDate) 
from
    Client
group by 
    clientName


推荐答案

不容易,因为Core Data首先是一个对象图。您可以通过抓取一组不同的名称,然后通过排序查询每个的最大值。

No not easily since Core Data is an object graph first. You could do it by grabbing a distinct set of the names and then querying for the max for each via a sort.

最好的答案是将它分成两个表

The best answer is to break it into two tables otherwise it is going to be computationally expensive each time you try and resolve this.

Don认为它是一个OR / M层。核心数据是一个对象图;全停。

Don't think of it as an OR/M layer. Core Data is an object graph; full stop.

事实上,它恰好存在于数据库结构中作为其持久化选项之一。

The fact that it happens to persist to a database structure as one of its persistence options is secondary.

你的问题的问题是,你试图使用对象图作为数据库。在这种情况下,我得使用一个非常频繁归因于我的阶段:

The issue in your question is that you are trying to use an Object Graph as a database. In that situation I get to use a phase that is very frequently attributed to me:

你做错了。 :)

这篇关于核心数据谓词与组和MAX()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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