带有2个组条件的Xcode NSManagedObject查询

带有2个组条件的Xcode NSManagedObject查询,xcode,core-data,group-by,nsmanagedobject,Xcode,Core Data,Group By,Nsmanagedobject,我正在尝试使用NSManagedObjects复制此查询: SELECT t1.znumber, t2.znumber, AVG(t1.zaroma) FROM zcuppings t1 LEFT JOIN zrounds t2 ON (t1.zround=t2.z_pk) LEFT JOIN zexaminees t3 ON (t2.zexaminee=t3.z_pk) WHERE t3.zcourse =

我正在尝试使用NSManagedObjects复制此查询:

    SELECT 
      t1.znumber, t2.znumber, AVG(t1.zaroma)
    FROM 
      zcuppings t1
      LEFT JOIN zrounds t2 ON (t1.zround=t2.z_pk)
      LEFT JOIN zexaminees t3 ON (t2.zexaminee=t3.z_pk)
    WHERE
      t3.zcourse = 1
    GROUP BY 
      t1.znumber, t2.znumber
像这样:

NSFetchRequest* fetch = [NSFetchRequest fetchRequestWithEntityName:@"Cuppings"];
fetch.predicate = [NSPredicate predicateWithFormat:@"round.examinee.course == %i",1];
NSEntityDescription* entity = [NSEntityDescription entityForName:@"Cuppings"
                                        inManagedObjectContext:managedObjectContext];
NSAttributeDescription* group = [entity.attributesByName objectForKey:@"number"];
NSAttributeDescription* group2 = [entity.attributesByName objectForKey:@"round.number"];
NSExpression *keyPathExpression = [NSExpression expressionForKeyPath: @"aroma"];
NSExpression *exprAVG = [NSExpression expressionForFunction: @"average:"
                      arguments: [NSArray   arrayWithObject:keyPathExpression]];
NSExpressionDescription *exprDescription = [[NSExpressionDescription alloc] init];
[exprDescription setName: @"avgAroma"];
[exprDescription setExpression: exprAVG];
[exprDescription setExpressionResultType:NSDecimalAttributeType];

[fetch setPropertiesToFetch:[NSArray arrayWithObjects:group, group2, 
  exprDescription, nil]];
[fetch setPropertiesToGroupBy:[NSArray arrayWithObjects:group, group2, nil]];
[fetch setResultType:NSDictionaryResultType];
NSError* error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:fetch error:&error];
NSLog(@"%@", results);

但是group2等于零,我只得到“number”字段。。。我做错了什么?

请在此处附上db方案截图。以下是db方案的截图: