首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >核心数据中的strftime SQL函数

核心数据中的strftime SQL函数
EN

Stack Overflow用户
提问于 2016-01-23 06:46:05
回答 1查看 150关注 0票数 0

我正在尝试获取核心数据,其中我按我的资产日期的月份进行分组。

在SQL中

代码语言:javascript
运行
复制
SELECT      SUM(total) as value,
            date as date,
            strftime('%m-%Y', date) as convertDate  
FROM        table
GROUP BY    convertDate 

我没有看到任何可以使用strftime的函数。有没有一种方法可以用NSFetchRequest代替NSFetchedResultController

EN

回答 1

Stack Overflow用户

发布于 2016-01-23 08:12:25

您可以使用NSExpressionDescription来完成此操作

有关使用NSFetchRequest进行分组的信息,您可以查看this tutorial或此stackOverFlow question

对于此处要添加到NSFetchRequest的NSExpressionDescription的总和

代码语言:javascript
运行
复制
NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
expressionDescription.name = @"sumOfAmounts";
expressionDescription.expression = [NSExpression expressionForKeyPath:@"@sum.total"];
expressionDescription.expressionResultType = NSDecimalAttributeType;

对于日期,我认为您可以在获取获取记录时使用NSDateFormatter对其进行格式化。

让我知道这是否有帮助:)

更新

代码语言:javascript
运行
复制
[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];
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34957217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档