Junior — Senior
Get the latest percentage values for each payout point
livecode
Task condition
You need to write an SQL query that returns the most recent value of the percent column for each pickpoint_id. For each record, select the row with the maximum date in the created field. Example table structure and expected result:
CREATE TABLE pickpoint_tariff (
id bigserial,
created timestamp DEFAULT now(),
pickpoint_id bigint,
percent numeric
);
created | pickpoint_id | percent
-------------+--------------+---------
2024-01-01 | 1 | 2
2024-01-01 | 2 | 2
2024-01-01 | 3 | 2
2024-01-02 | 1 | 1
2024-01-02 | 2 | 1
2024-01-02 | 3 | 3
2024-01-03 | 1 | 3
2024-01-03 | 2 | 10
2024-01-04 | 2 | 20
2024-01-04 | 3 | 30
Expected output:
1 — 3
2 — 20
3 — 30