|  | zdravim,  rad by som poziadal o pomoc. Mam tabulku z ktorej potrebujem spravit vystup a neviem ako, viete mi niekto pomoct? Tabulka: 
col1	col2	col3
1	A11	A1
2	A11	A1
3	A13	A1
4	A13	A1
5	B12	B12
6	B12	B12
7	B12	B12
8	B12	B12
9	B13	B1
10	B13	B1
11	B14	B1
12	B14	B1
13	B14	B1
14	B13	B1
15	B13	B1
16	B13	B1
 
Vystup ktory potrebujem:
A	B	C	D	                        E
1	4	A1	A11 - 2, A13 - 2 	        4
5	8	B12	B12 - 4	                        4
9	16	B1	B12 - 2, B14 - 3, B13 -3	8
 
public class sample
{
  public int col1 {get; set;}
  public string col2 {get; set;}
  public string col3 {get; set;}
} 
List<sample> sampleData = new List<sample>() {
        new sample {col1 =1, col2 ="A11", col3="A1"}, 
        new sample {col1 =2, col2 ="A11", col3="A1"}, 
        new sample {col1 =3, col2 ="A13", col3="A1"}, 
        new sample {col1 =4, col2 ="A13", col3="A1"},
        new sample {col1 =5, col2 ="B12", col3="B12"}, 
        new sample {col1 =6, col2 ="B12", col3="B12"}, 
        new sample {col1 =7, col2 ="B12", col3="B12"},
        new sample {col1 =8, col2 ="B12", col3="B12"}, 
        new sample {col1 =9, col2 ="B13", col3="B1"},
        new sample {col1 =10, col2 ="B13", col3="B1"}, 
        new sample {col1 =11, col2 ="B14", col3="B1"}, 
        new sample {col1 =12, col2 ="B14", col3="B1"}, 
        new sample {col1 =13, col2 ="B14", col3="B1"}, 
        new sample {col1 =14, col2 ="B13", col3="B1"}, 
        new sample {col1 =15, col2 ="B13", col3="B1"}, 
        new sample {col1 =16, col2 ="B13", col3="B1"}
        };
var groupLineToImport = sampleData.AsEnumerable()
                        .GroupBy(
                        g => new
                        {
                            SortTo = g.col3
                        })
                        .Select(r => new
                        {
                            MinPor = r.Min(t => t.col1),
                            MaxPor = r.Max(t => t.col1),
                            GroupCode = r.Key,
                            Pocet = r.Count(),
                        });
groupLineToImport.ToList().ForEach(p=> Console.WriteLine(p));
Vystup co viem spravit je pre stlpec A,B,C a E: 
{ MinPor = 1, MaxPor = 4, GroupCode = { SortTo = A1 }, Pocet = 4 }
{ MinPor = 5, MaxPor = 8, GroupCode = { SortTo = B12 }, Pocet = 4 }
{ MinPor = 9, MaxPor = 16, GroupCode = { SortTo = B1 }, Pocet = 8 }
potrebujem ale dosiahnuit este aj pre stlpec D: 
{ MinPor = 1, MaxPor = 4, GroupCode = { SortTo = A1 },List = {A11 - 2, A13 - 2}, Pocet = 4 }
{ MinPor = 5, MaxPor = 8, GroupCode = { SortTo = B12 }, List = {B12 - 4}, Pocet = 4 }
{ MinPor = 9, MaxPor = 16, GroupCode = { SortTo = B1 }, List = {B12 - 2, B14 - 3, B13 - 3}, Pocet = 8 }
Vieste mi niekto poradit ako? Dakujem za navrhy .... |