获取数据单表形式父子查询pos_parent_id表作为子ID

时间:2017-12-18 11:15:22

标签: php mysql

我的表名是forum_posts

enter image description here

我将在子子ID

之后的第一个parent_id获取数据

表示post_id

40
41
42
43
44
48(这里post_parent_id = 44)
49(这里post_parent_id = 44)
45
47(这里post_parent_id = 45)
46 50(这里post_parent_id = 46)

你可以帮助它如何实现

1 个答案:

答案 0 :(得分:0)

类似的东西:

   var result = list1
     .Concat(list2
        .Select(pair => new KeyValuePair<DateTime, int>(pair.Key, -pair.Value)))
     .GroupBy(pair => pair.Key, 
              pair => pair.Value)
     .Select(chunk => new KeyValuePair<DateTime, int>(chunk.Key, chunk.Sum()))
     .OrderBy(pair => pair.Key);