小编Bit*_*are的帖子

NSBatchDeleteRequest导致合并冲突

我有一个应用程序,它将与服务器同步,并每天更新数据。在同步期间,我删除了某些实体的所有数据,并重新加载了新数据。我正在使用以下代码:

    func SyncronizeUserComments(theData : [[AnyHashable : Any]])
{
    // Delete User Comments for this User and Connection
    let commentRequest : NSFetchRequest<NSFetchRequestResult> = PT_UserComments.fetchRequest()
    commentRequest.predicate = NSPredicate(format: "connection = %@ AND user == %@", Global_CurrentConnection!, Global_CurrentUser!)
    coreData.processDeleteRequest(request: commentRequest)

    // ADD the Comments to CoreData
    for index in 0..<theData.count {
        let result : [AnyHashable : Any] = theData[index]
        if let commentID = result["Comment_ID"] as? String, let commentText = result["Comment_Text"] as? String, let commentTitle = result["Comment_Title"] as? String
        {
            let newUserComment = PT_UserComments(context: …
Run Code Online (Sandbox Code Playgroud)

core-data ios swift swift4 xcode9

5
推荐指数
1
解决办法
212
查看次数

在查询中选择TOP 20 Distinct Rows

我在带有日期戳的表中记录了用户操作.

每次用户进入项目时,都会记录他们查看该项目并标记日期时间.

我想获得用户最后进入的TOP 20项目.

这是我到目前为止:

SELECT DISTINCT TOP (20) Users_Tran_ID
FROM App_UserLog
WHERE (Users_ID = 'ADMIN') AND (Users_Transaction LIKE 'Permit Viewed%')
ORDER BY App_UserLog.Users_LogDate DESC
Run Code Online (Sandbox Code Playgroud)

问题是,我不想在输出中使用Users_LogDate,因为我需要UNIQUE Users_Tran_ID.

当我从SELECT中删除Users_LogDate时,我收到以下错误:

ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Run Code Online (Sandbox Code Playgroud)

这是我得到的基本选择和结果集.我只想要不同的Users_Tran_ID,只需要TOP 20.

ADMIN   Permit Viewed   B2011-0012  2013-08-29 17:35:04.000
ADMIN   Permit Viewed   B2011-0012  2013-08-29 17:29:09.000
ADMIN   Permit Viewed   B2006-0043  2013-08-29 17:29:05.000
ADMIN   Permit Viewed   B2011-0012  2013-08-29 17:28:49.000
ADMIN   Permit Viewed   B2008-0167  2013-08-29 17:17:13.000
ADMIN   Permit Viewed   B2006-0043  2013-08-29 17:17:08.000 …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

core-data ×1

ios ×1

sql ×1

sql-server ×1

swift ×1

swift4 ×1

xcode9 ×1