下面我有表 - 由名並從每個組只返回一個記錄最大ID公司將行分組並從每個組中獲取最大值。
id name value year
1 IBM 10 2011
2 IBM 30 2012
3 IBM 10 2012
4 C 10 2010
我想組記錄。所有結果合併到2011年使用linq的公司列表中。對於我的示例輸出結果應該是 - 「3 IBM 10 2012」
我寫了一些內容,但無法正常工作。
var a = from x in companies where x.year > 2011
group x by new {x.name, x.value, x.ID, x.year } into g
select new {
g.Key.name,
g.Key.value,
g.Max(a=>a.ID),
g.Key.value
};
return a.ToList();
你的意思是你希望它返回「3 IBM 10 2012」,是嗎? – WEFX
你想按x.ID分組嗎? –
是的,我的意思是返回「3 IBM 10 2012」 – user570715