1

实际查询:-

SELECT *,COUNT(case when ZISREAD = 0 then ZISREAD end) FROM ZNOTIFICATION WHERE ZTTL>1411025900  group by zkind,zaction,zname

嗨,我需要COUNT(case when ZISREAD = 0 then ZISREAD end)使用核心数据转换计数条件NSExpression

 NSExpression *countPathExpression = [NSExpression expressionForKeyPath: @"isRead"];

 NSExpression *countExpression = [NSExpression expressionForFunction: @"count:"
                                                              arguments: [NSArray arrayWithObject:countPathExpression]];

    NSExpressionDescription *countExpressionDescription = [[NSExpressionDescription alloc] init];
    [countExpressionDescription setName: @"count"];
    [countExpressionDescription setExpression: countExpression];
    [countExpressionDescription setExpressionResultType: NSInteger32AttributeType];

COUNT(case when ZISREAD = 0 then ZISREAD end)我需要帮助人们转换NSExpression

4

1 回答 1

0

首先,您可以在 fetch 请求中添加一个谓词:

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"isRead = NO"];

然后你想在要获取的属性中指定你的表达式:

fetchRequest.propertiesToFetch = @[countExpression];

不要忘记设置结果类型

fetchRequest.resultType = NSDictionaryResultType;

那应该让你继续前进。请记住,如果要跨属性评估表达式,还可以使用 propertiesToGroupBy 数组,例如按天分组,这将允许您查看每天的计数:)

快乐编码

于 2014-09-23T17:20:07.330 回答