linq2sql与组和连接

时间:2012-09-27 10:17:56

标签: vb.net linq join linq-to-sql group-by

如何在linq(VB)中编写此查询

select 
    g.* 
from PROB_GROUP g 
inner join 
(
    select 
        PGR_NAME, 
        PGR_PCELL, 
        max(PGR_VERSION) max_version 
    from PROB_GROUP 
    group by PGR_NAME, PGR_PCELL
) grouped_g 
on g.PGR_NAME = grouped_g.PGR_NAME 
    and g.PGR_PCELL = grouped_g.PGR_PCELL 
    and g.PGR_VERSION = grouped_g.max_version 
order by g.PGR_TYPE, g.PGR_NAME

1 个答案:

答案 0 :(得分:0)

得到它

From pp In DB.PROB_GROUPs Join p1 In
 (From p In DB.PROB_GROUPs Group By p.PGR_NAME, p.PGR_PCELL Into g = Group Select PGR_NAME, PGR_PCELL, H_VERSION = g.Max(Function(p) p.PGR_VERSION))
 On p1.H_VERSION Equals pp.PGR_VERSION And p1.PGR_NAME Equals pp.PGR_NAME And p1.PGR_PCELL Equals pp.PGR_PCELL Select pp Order By pp.PGR_TYPE, pp.PGR_NAME

应该没事吧?