CoreData相当于sum ... group by

时间:2009-05-26 02:29:32

标签: iphone core-data

我有以下伪SQL架构:

table flight
  id int primary key
  date timestamp
  aircraft_id int (foreign key to aircraft.id)

table flight_component
  flight_id int (foreign key to flight.id)
  component_id int (foreign key to component.id)
  duration double

如果我将其转换为使用CoreData,是否有一种等效方法可以使用另一个查询谓词获取每个组件的总持续时间?我认为SQL等价物是

select component_id, sum(duration)
from flight_component
join flight on (flight_component.flight_id = flight.id)
where flight.date between ? and ?
group by component_id

或者我将不得不进行查询,然后自己总结所有组件?

1 个答案:

答案 0 :(得分:6)

您可以查询@“someArray。@ sum”。 Collection Operators页面上有这样的运营商列表。