CoreData equivalent to sum ... group by

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 a different query predicate? I think the SQL equivalent will 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 will I need to make my request and then summarize all the components myself?

+3
source share
1 answer

You can request for @ "someArray. @Sum". There is a list of such operators on the Collection Operators page .

+6
source

Source: https://habr.com/ru/post/1709047/


All Articles