这是模拟的
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];
在这里找到
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)