核心数据:两个属性的GROUP BY SUM

时间:2014-02-03 15:18:26

标签: ios iphone objective-c core-data

您知道是否可以 GROUP fetchRequest BY 2个属性的 SUM

我已经尝试过:

[request setPropertiesToGroupBy:@[@"senderUserId + receiverUserId"]];

此外:

NSExpression *sumExpr = [NSExpression expressionForFunction:@"add:to:" arguments:[NSArray arrayWithObjects:[NSExpression expressionForKeyPath:@"senderUserId"], [NSExpression expressionForKeyPath:@"receiverUserId"], nil]];
NSExpressionDescription *sum = [[NSExpressionDescription alloc] init];
[sum setName:@"sum"];
[sum setExpression:sumExpr];
[sum setExpressionResultType:NSInteger64AttributeType];

[request setPropertiesToGroupBy:@[sum]];

有什么建议吗? 谢谢!

0 个答案:

没有答案