Hello I am trying to figure out how to transform this table
+----+------------+-------+-------+---------------------+
| id | profile_id | name | value | added |
+----+------------+-------+-------+---------------------+
| 1 | 1 | Item1 | 100 | 2018-11-30 17:08:38 |
| 2 | 1 | Item1 | 140 | 2018-11-30 17:18:38 |
| 3 | 1 | Item2 | 120 | 2018-11-28 17:08:38 |
| 4 | 2 | Item1 | 110 | 2018-11-03 17:08:38 |
| 5 | 3 | Item3 | 120 | 2018-11-30 17:08:38 |
| 6 | 3 | Item4 | 100 | 2018-11-29 17:08:38 |
+----+------------+-------+-------+---------------------+
Into something like this
+----+------------+-------+-------+---------------------+
| id | profile_id | name | value | added |
+----+------------+-------+-------+---------------------+
| 2 | 1 | Item1 | 140 | 2018-11-30 17:18:38 |
| 3 | 1 | Item2 | 120 | 2018-11-28 17:08:38 |
| 5 | 3 | Item3 | 120 | 2018-11-30 17:08:38 |
| 6 | 3 | Item4 | 100 | 2018-11-29 17:08:38 |
+----+------------+-------+-------+---------------------+
Basically, it should display Unique 'name' and 'profile_id' (display maximum value of the 'value' field for a given name). I tried something like this
SELECT DISTINCT(t.profile_id),t.name,t.value FROM table as t ORDER BY t.value DESC;
There should be also a where clause that the added date cannot be older than 7d ays.
Further explanation: a profile_id can have the same names stored, only the value and added time will change. It should return only a unique name and the highest found value.
If I am not clear feel free to ask for more details.
Help is appreciated.