根据关系表从父表获取记录 - CoreData
抱歉,如果标题没有任何意义。
让我进一步解释一下。
我有这个 CoreData 应用程序,而且我对 CoreData 还比较陌生。我有两张桌子。一是预算,一是支出。因此预算表有一个名为 TotalBudget 的字段。现在,我在支出表中有不同的行,用户随时间输入这些行,并且该表有一个名为“个人支出”的字段。
现在我希望做的是只获得个人支出总和小于总预算(预算表)的预算。在 SQL 语言中,它会类似于下面的内容
Select BudgetName 从预算来看 其中总预算 < (从支出中选择 Sum(IndividualBudget),其中 BudgetID = Budget.BudgetID)
如何在核心数据中实现这一目标?我有从一个表中检索数据的代码,我可以使用 NSPredicate 根据 BudgetStartDate 和 BudgetEndDate 过滤记录,但我怎样才能实现类似的目标。
谢谢
Sorry if title does not make any sense.
Let me explain it a bit further.
I have this CoreData application and I am relatively new in CoreData. I have two tables. One is Budget and one is Spending. So Budget table has a field called TotalBudget. Now I have different rows in Spending Table which user input over the time and this table has a field called Individual Spend.
Now what I am hoping to do is to get only those budgets where Sum of Individual Spend is less than TotalBudget (Budget table). In SQL language it would be something like below
Select BudgetName
From Budget
Where TotalBudget < (Select Sum(IndividualBudget) From Spend Where BudgetID = Budget.BudgetID)
How can I achieve that in core data? I have the code to retrieve data from one table and I can use NSPredicate to filter records based to BudgetStartDate and BudgetEndDate but how can I achieve something like that.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设以下对象模型:
这将为您提供一组预算实体,其中支出金额 >预算金额:
Assuming following object model:
This will get you an array of Budget entities where the spend amount is > budget amount: