I want to write something like this:
select
"id",
"plant",
"product",
"uom",
count(*) as transactions_count,
avg(("invoice_price" / "quantity")) filter (where ("date" == max(date)) as "LAST_GUIDANCE", -- I want group by date only for this
from "transactions"
group by
"id",
"plant",
"product",
"uom"
Where I want to count last guidance but only for rows with last date.
Problem is that I cannot add "date" to group by, because I want this grouping only for last_guidance.. It is possible to write it somehow easily in Postgres (use "over" for ex.) or I have to create too separated queries and then join them?
Thanks for answers