select distinct on ("date", location_code, product_code, type)
"date",
location_code,
product_code,
quantity,
type,
updated_at
from transactions t
order by t."date", t.location_code, t.product_code, t.type, t.updated_at desc
select distinct on ("date", location_code, product_code, type)
"date",
location_code,
product_code,
quantity,
type,
updated_at
from transactions t
order by t."date", t.location_code, t.product_code, t.type, t.updated_at desc