查询核心数据中的每个第 n 个元素

发布于 2024-11-27 10:22:44 字数 189 浏览 6 评论 0原文

如何查询核心数据中的每个 nTh(或每秒)元素?

这是我在 SQL 中要做的事情:

SELECT * FROM TABLE_NAME 
WHERE (ROWID, 0) IN (SELECT ROWID, MOD(ROWID, N) FROM TABLE_NAME);

提前谢谢。

How do I query for every nTh (or just every second) Element in Core Data?

Here is what I would do in SQL:

SELECT * FROM TABLE_NAME 
WHERE (ROWID, 0) IN (SELECT ROWID, MOD(ROWID, N) FROM TABLE_NAME);

Thx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-12-04 10:22:44

你不能。

核心数据不是 SQL。实体不是表。对象不是行。属性不是列。关系不是连接。 Core Data 是一个对象图管理系统,它可能会也可能不会持久化对象图,并且可能会也可能不会在幕后使用 SQL 来执行此操作。尝试用 SQL 术语来思考 Core Data 将会导致您完全误解 Core Data,并导致很多痛苦和浪费时间。

托管对象并不作为表中的“元素”存在,而是存在于对象图中,对象图中是通过数据模型中定义的关系连接的各个对象的网络。即使您使用 SQL 存储选项,分解对象属性在表中的实际物理位置也与对象在对象图中的位置无关。

如果您想要每个第 n 个对象,您将首先使用排序描述符进行提取,按照您当前想要的任何标准对对象进行排序,然后您将获取提取返回的数组中的每个第 n 个元素。

You can't.

Core Data is not SQL. Entities are not tables. Objects are not rows. Attributes are not columns. Relationships are not joins. Core Data is an object graph management system that may or may not persist the object graph and may or may not use SQL far behind the scenes to do so. Trying to think of Core Data in SQL terms will cause you to completely misunderstand Core Data and result in much grief and wasted time.

Managed Objects do not exist as "elements" in a table but in an object graph which is a web of individual objects connected by the relationships defined in your data model. Even if you use the option of an SQL store, the actually physical position of the decomposed object's attributes in the table will have nothing to do with object's location in the object graph.

If you want every nth object, you would first do a fetch with a sort descriptor ordering the objects by whatever criteria you want at the moment and then you would take every nth element of the array returned by the fetch.

只是在用心讲痛 2024-12-04 10:22:44

SELECT * FROM table_name WHERE mod(ROWID,2)=0

如果 ROWID 是表中的字段,则 。请注意,表中的行没有“序列号”,尽管您可以在查询结果中构造序数

SELECT * FROM table_name WHERE mod(ROWID,2)=0

if ROWID is a field in the table. Note that rows in a table have no "sequence number", although you may construct a ordinal in the query result

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文