我是linq的新手。從下面的數據列表中,幫助我如何應用Group by和 其他構造來實現如下所示的預期輸出。C#LINQ - 如何應用group?
List<SalesAnalysis> AnaList = new List<SalesAnalysis>();
AnaList.Add(new SalesAnalysis("P001", 2009, 45000));
AnaList.Add(new SalesAnalysis("P001", 2008, 13000));
AnaList.Add(new SalesAnalysis("P002", 2009, 5000));
AnaList.Add(new SalesAnalysis("P002", 2008, 15000));
AnaList.Add(new SalesAnalysis("P003", 2009, 25000));
AnaList.Add(new SalesAnalysis("P003", 2008, 65000));
AnaList.Add(new SalesAnalysis("P004", 2009, 5000));
AnaList.Add(new SalesAnalysis("P004", 2008, 3000));
AnaList.Add(new SalesAnalysis("P004", 2007, 95000));
AnaList.Add(new SalesAnalysis("P004", 2006, 83000));
class SalesAnalysis
{
public string ProductCode
{
get;
set;
}
public int Year
{
get;
set;
}
public int NumberOfUnitsSold
{
get;
set;
}
public SalesAnalysis(string productcode, int year,
int numberofunitssold)
{
ProductCode = productcode;
Year = year;
NumberOfUnitsSold = numberofunitssold;
}
}
條件:
1)報告只需要在2008年全年和2009年只有
2)Numberofunits> = 30000是頂級機芯產品
3)Numberofunits> = 10000 < 30000是平均運動產品
4)單元數量< 10000差動產品
預期輸出:
Top Movement
Product Code Year Numberofunits
P003 2008 65000
P001 2009 45000
Average Movement
Product Code Year Numberofunits
P003 2009 25000
P002 2008 15000
P001 2008 13000
Poor Movement
Product Code Year Numberofunits
P002 2009 5000
P004 2009 5000
P004 2008 3000
我是誰讀 「Analist」 的頁面上的第一件事情唯一的一個!? – cwap 2009-12-01 20:04:59
您的銷售數據已經分組 - 看起來您需要Where和OrderBy? – 2009-12-01 20:05:27