相当于核心数据的GROUP BY

相当于核心数据的GROUP BY,第1张

相当于核心数据的GROUP BY

这是模拟的

SELECt 'Status', COUNT(*) FROM 'Records' GROUP BY 'Status'

NSFetchRequest* fetch = [NSFetchRequest fetchRequestWithEntityName:@"Record"];NSEntityDescription* entity = [NSEntityDescription entityForName:@"Record"         inManagedObjectContext:myManagedObjectContext];NSAttributeDescription* statusDesc = [entity.attributesByName objectForKey:@"status"];NSexpression *keyPathexpression = [NSexpression expressionForKeyPath: @"url"]; // Does not really matterNSexpression *countexpression = [NSexpression expressionForFunction: @"count:"   arguments: [NSArray arrayWithObject:keyPathexpression]];NSexpressionDescription *expressionDescription = [[NSexpressionDescription alloc] init];[expressionDescription setName: @"count"];[expressionDescription setexpression: countexpression];[expressionDescription setexpressionResultType: NSInteger32AttributeType];[fetch setPropertiesToFetch:[NSArray arrayWithObjects:statusDesc, expressionDescription, nil]];[fetch setPropertiesToGroupBy:[NSArray arrayWithObject:statusDesc]];[fetch setResultType:NSDictionaryResultType];NSError* error = nil;NSArray *results = [myManagedObjectContext executeFetchRequest:fetch  error:&error];

在这里找到



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5107703.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存