I currently have the below postgres query. With one aggregation subquery. I am not seasoned developer and apologies if I am not explaining this very well.
select