Linq query to select the group of student names ids based on marks

Hi All,

Scenario- I have 1 datatable which contains columns namely student name, id and marks.

I have to select all the ids if any of the marks is less than 40 related to that student. it may have multiple student names, ids and marks, below table for reference.

Student name Id Marks
Abc 101 55
Abc 102 54
Abc 103 39
Abc 104 56
Xyz 105 66
XYz 106 65

in the above table one of the marks is less than 40 so it has to consider all the ids for Abc.

Expected Output

Can anyone please help with linq query.

Thanks in Advance

arrIDs | StringArray =

(From d in YourDataTableVar.AsEnumerable()
Group d by k=d("StudentName").toString.Trim into grp=Group
Where grp.Any(Function (g) CInt(g("Marks").toString.Trim) < 40)
Let idl = grp.Select(Function (x) x("ID").toString.Trim)
Select ids =idl).SelectMany(Function (x) x).toArray

Hi @M1288

Try this syntax:

(From row In Dt_input.AsEnumerable()
               Group row By studentName = row("Student Name")
               Into studentGroup = Group
               Where studentGroup.Any(Function(r) Convert.ToInt32(r("Marks")) < 40)
               From sg In studentGroup
               Select (Convert.ToInt32(sg("ID")).ToString)).ToList

Shared the workflow for reference too.
Sequence5.xaml (12.9 KB)


Hope it helps!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.