Here’s the relation table
StudentName
Course
Marks
Peter
Bio
65
Peter
Chem
70
Peter
Music
80
David
Chem
50
How can I make something like the followings
Peter Total : 215
Subject : Bio - 65
Subject : Chem - 70
Subject : Music - 80
Peter Total : 50
Subject : Chem - 50
I would not use a subreport for this as this can be achieved in a simpler way: You can utilize Report groups and variables to achieve this. Make sure that the data is sorted accordingly to the output.
Preparation
Student), select fieldStudentNameas group expression, add header but no footer.Report Design
StudentNamefrom the report inspector into the report designer into the Student group header band. There will be a popup asking what kind of value shall be displayed, select The field value and click Ok.Drag and drop the Variable
totalMarksByStudentfrom the report inspector into the report designer into the Student group header band. Click on the text field and modify following settings in the properties panel:200(to allow more space)"Total : " + $V{totalMarkByStudent}java.lang.StringGroup(meaning that the value gets evaluated once the processing of the group is finished)StudentDrag and drop the fields Course and Marks from the report inspector into the detail band in the report designer. Right click on the course field and select Edit Expression. CHange the expression to
"Subject : " + $F{Course}and click on Apply.With this configuration you achieve a report output as in the image below.

For further reference here the complete JRXML using report group and variable:
If you use a subreport instead
I assume that the subreport is paraemterized with the student id shows the data for a given student. The main report shows the field
StudentNameand the subreport in the detail panel.totalin the subreport that calculates the total for the student.totalByStudentin the main report with calculation type set toSystem.totalByStudentinto the detail band. Select it and in the Properties panel set Evaluation time to Band. The output will be the same as shown above.I recommend to use the approach with report group and variable as it reduces the complexity of the report, as well as performance for this way would be better.