0

I have this data in a MySQL table

+---------+--------+------------+---------------------+
| student | course | allocation |    time_created     |
+---------+--------+------------+---------------------+
|       1 |      1 |        0.2 | 2020-01-01 00:00:00 |
|       1 |      2 |        0.4 | 2020-01-01 00:00:00 |
|       1 |      3 |        0.6 | 2020-01-01 00:00:00 |
|       1 |      2 |        0.9 | 2021-01-01 00:00:00 |
+---------+--------+------------+---------------------+

The first three rows are added in 2020 and correspond to allocations of student 1 for the courses 1, 2, and 3. The fourth row is added in 2021 and updated the allocation for the course 2 to 0.9.

My question is how do I get the latest value of the allocation for each pair of (student, course).

(Latest = Latest time_created)

I tried to use a simple groupby but I can't get the maximum value of allocation for a set of (student, course)

Bill Karwin
  • 499,602
  • 82
  • 638
  • 795
kaushalpranav
  • 1,509
  • 20
  • 31

0 Answers0