I am new to linq.From the list of following data,help me how can i apply Group by and other construct to achieve the expected output as given below.
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;
}
}
conditions :
1) Report only needed for the year 2008 and 2009 only
2) Numberofunits >=30000 are Top Movement products
3) Numberofunits >=10000 to < 30000 are average movement products
4) Numberofunits <10000 are poor moving product
Expected output:
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