代码之家  ›  专栏  ›  技术社区  ›  Andreas

分组与亚音速3

  •  0
  • Andreas  · 技术社区  · 16 年前

    Id   Group   Priority
     1       1         0
     2       2         0
     3       3         0
     4       2         1
     5       1         1
     6       2         2
     7       3         1
    

    Id   Group   Priority
     5       1          1
     6       2          2
     7       3          1
    

    sql看起来像这样:

    SELECT *
    FROM   GroupPriority
    WHERE  (Priority =
                      (SELECT  MAX(Priority)
                       FROM    GroupPriority
                       WHERE   (Group = GroupPriority.Group)))
    

    1 回复  |  直到 16 年前
        1
  •  0
  •   Andreas    16 年前

        var group_query = new Query<GroupPriority>(provider);
        var items = from gp in group_query
                    where gp.Priority == 
                        (from gp_sub in group_query
                         where gp_sub.Group == gp.Group
                         select gp_sub.Priority).Max()
                    select gp;
    
    推荐文章