Pippo 1 010 NA AA
Pippo 1 010 NA AA
Pippo 1 010 TO CC
Pluto 2 011 RM AA
Pluto 2 011 TO BB
Pluto 2 011 RM BB
Pluto 2 011 RM CC
I need as output the following table:
Library ID_1 ID_2 No. Books Detail
Pippo 1 010 3 #2 NA, #1 TO
Pluto 2 011 4 #3 RM, #1 TO
I have tried to generate a key composed of key=“Library + City”. Add this field to the datable, then use the first query to compute the count of books for the new “key”, and
again a second query to compute the total for Library.
I know that there is a simple way to do the process with a single query using “concatenate” but I am not able to write it correctly.
(From d In dtData.AsEnumerable
Group d By k=d("LIB").toString.Trim Into grp=Group
Let cnt = grp.Count
Let dctDet = grp.GroupBy(Function (g1) g1("City").toString.Trim).ToDictionary(Function (lk) lk.Key, Function (lk) lk.count)
Let strDet = String.Join(",", dctDet.Select(Function (kvp) String.Format("#{0} {1}", kvp.Value.ToString, kvp.Key)))
Let ra = grp.First.ItemArray.Take(3).Concat({cnt, strDet}).ToArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable
Dont fear the LINQ as we can take it also and decompose it into a NON-LINQ implementation.