views:

1273

answers:

1

I have the following pseudo-SQL schema:

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

If I convert this to using CoreData, is there an equivalent way to get the total duration for each component with another query predicate? I think the SQL equivalent would be

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

Or am I going to have to make my query and then sum up all the components myself?

+2  A: 

You can query for @"someArray.@sum". There's a list of such operators on the Set and Array Operators page.

Rob Napier