1
我有以下結構數據:
var lookupDictionary = new Dictionary<string, Dictionary<string, double>>();
我想寫一個Linq查詢,通過對內部字典中的雙精度進行總結和排序,爲我提供外部字典中的前10個鍵ionary。我很好地掌握了SQL中的group by
,但很難將其轉換爲Linq。
任何可以演示此類查詢的Linq專家?
我有以下結構數據:
var lookupDictionary = new Dictionary<string, Dictionary<string, double>>();
我想寫一個Linq查詢,通過對內部字典中的雙精度進行總結和排序,爲我提供外部字典中的前10個鍵ionary。我很好地掌握了SQL中的group by
,但很難將其轉換爲Linq。
任何可以演示此類查詢的Linq專家?
你需要一組嗎?
var top = lookupDictionary
.Select(dict => new { dict.Key, InnerCount = dict.Value.Values.Sum() })
.OrderByDescending(dict => dict.InnerCount)
.Take(10);
Dictionary<string, Dictionary<string, double>> lookupDictionary = new Dictionary<string, Dictionary<string, double>>();
lookupDictionary.Select(outerKeyPair => new
{
Key = outerKeyPair.Key,
Sum = outerKeyPair.Value.Values.Sum()
})
.OrderByDescending(pair => pair.Sum)
.Take(10);
http://stackoverflow.com/questions/1575316/linq-top-value-form-each-group – paragy
這將真正讓事情更清晰,如果你可以給你的樣品輸入和預期輸出的一個例子。 –
另外,http://www.WhatHaveYouTried.com/ – cadrell0