I have a table named assets:
create table assets (
id bigint primary key,
name varchar(255) not null,
value double precision not null,
business_time timestamp with time zone,
insert_time timestamp with time zone default now() not null
);
I am trying to write a query to get the most recent value
for each day based on business_time
. This is a sample query that I wrote:
select distinct on (business_time::date) business_time::date, value
from home.assets
where name = 'USD_RLS'
order by business_time::date desc
But the value for each day is not always the most recent one. I guess it's a bit random which value I get for each day. Any idea how I could fix this query?