如何获取更新的源自顶部,谁的feed获取评论来自sql server的顶部?

时间:2017-05-11 06:50:52

标签: sql-server

我为Feed列表创建了一个商店程序。我想根据选项卡的顶部提供更新的日期时间,然后在谁提供评论之后获得评论,评论提要来自顶部,一步更少的更新提要。所以现在第一个饲料是评论饲料,第二个是更新饲料这样我想饲料list.so我写这个查询,但没有得到饲料的预期列表。

这是我的查询=>

SELECT Tab.* FROM (
       SELECT 
       C.CaseId,                                 
        ISNULL((SELECT TOP(1)InsertDateTime FROM CaseComment WHERE CaseId = C.CaseId ORDER BY InsertDateTime DESC),getDate()) AS CommentInsertDateTime,
         row_number() over (partition by C.CaseId order by CC.InsertDateTime desc) as RawNumber,
       CC.InsertDateTime as CommentInsertDate,
       C.UpdateDateTime 
    FROM Case C     
    LEFT join CaseComment CC ON CC.CaseId = C.CaseId        
    WHERE C.IsApproved = 1
        AND C.IsDeleted = 0 ) Tab where RawNumber = 1 AND ORDER BY Tab.UpdateDateTime,Tab.CommentInsertDate DESC OFFSET (1- 1) * 20 ROWS
    FETCH NEXT 20 ROWS ONLY 

这是我的样本数据=> 表格案例:

Id | Description | InsertdateTime          | UpdateDateTime
1     feed1        2017-05-10 19:48:19.850   2017-05-11 19:48:19.850
2     feed2        2017-05-09 19:48:19.850   2017-05-10 19:48:19.850
3     feed3        2017-05-08 19:48:19.850   2017-05-19 19:48:19.850

Table CaseComment

 Id | CaseId | Comment | InsertDateTime
  1    2        test      2017-05-11 18:48:19.850
  1    2        test1     2017-05-10 17:48:19.850
  1    3        good      2017-05-09 19:48:19.850

我的预期o / p更新帖子=>

  Id | Description   | UpdateDateTime        | CommentInsertDateTime
  1     feed1        2017-05-11 19:48:19.850
  2     feed2        2017-05-10 19:48:19.850   2017-05-11 18:48:19.850
  3     feed3        2017-05-19 19:48:19.850   2017-05-09 19:48:19.850

我的预期o / p获得对案例ID 3的评论o / p =>

  Id | Description   | UpdateDateTime        | CommentInsertDateTime
   3     feed3        2017-05-19 19:48:19.850   2017-05-09 19:48:19.850
   1     feed1        2017-05-11 19:48:19.850
   2     feed2        2017-05-10 19:48:19.850   2017-05-11 18:48:19.850

1 个答案:

答案 0 :(得分:1)

检查此查询,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);


            var dates = doc.Descendants().Where(x => x.Name.LocalName.Contains("Date") && ((string)x != string.Empty));

            foreach (var date in dates)
            {
                date.SetValue(((DateTime)date).ToUniversalTime());
            }
        }
    }
}