{'name': 'student1', 'date': '2019-03-12', 'grade': 3}
{'name': 'student2', 'date': '2019-03-12', 'grade': 4}
{'name': 'student3', 'date': '2019-03-12', 'grade': 5}
{'name': 'student4', 'date': '2019-03-12', 'grade': 4}
{'name': 'student1', 'date': '2019-09-01', 'grade': 2}
{'name': 'student2', 'date': '2019-09-01', 'grade': 3}
{'name': 'student3', 'date': '2019-09-01', 'grade': 4}
Consider the above as my sample dataset wherein I'm able to query the data and generate list of students along with the latest grade, like below:
{'name': 'student1', 'date': '2019-09-01', 'grade': 2}
{'name': 'student2', 'date': '2019-09-01', 'grade': 3}
{'name': 'student3', 'date': '2019-09-01', 'grade': 4}
{'name': 'student4', 'date': '2019-03-12', 'grade': 4}
Issue arises, when I make a query to see the list of students who have grade 4, it gives me result as:
{'name': 'student2', 'date': '2019-03-12', 'grade': 4}
{'name': 'student3', 'date': '2019-09-01', 'grade': 4}
{'name': 'student4', 'date': '2019-03-12', 'grade': 4}
While I need to query only the latest record of students and get only two records since as per latest records, grade of student2 is 3 and total response expected is as below:
{'name': 'student3', 'date': '2019-09-01', 'grade': 4}
{'name': 'student4', 'date': '2019-03-12', 'grade': 4}
How can I achieve this result, so that I'm searching for grade 4 students considering the fact that only their latest record is being searched.