如何在 Core Data(iOS 开发)中进行这个 SQLite 查询?
SELECT DISTINCT VALUE_1, VALUE_2 FROM TABLE;
它应该返回 (duo, trio) 不同的值,例如,从此表中:
(123, 234, Car)
(123, 456, Bus)
(234, 456, Train)
(123, 456, Eletric Bus)
(234, 456, Subway)
它应该返回 3 行,因为(123, 234)
是 UNIQUE 等等(234, 456)
和(123, 456)
。
(123, 234, Car)
(234, 456, Train) or (234, 456, Subway)
(123, 456, Eletric Bus) or (123, 456, Bus)
使用此代码,我只能区分一个值:
NSDictionary *entityProperties = [entity propertiesByName];
[request setPropertiesToFetch:[NSArray arrayWithObject:[entityProperties objectForKey:@"VALUE_1"]]];
[request setReturnsDistinctResults:YES];
[request setResultType:NSDictionaryResultType];