sql - How to get lastest result for each of distinct list? -


i have postgresql table.

i can distinct products , brands:

select distinct product, brand list 

and after in django latest price:

for x in query:

select price list  product = x.product , brand = x.brand order ... limit 1 

how can of 1 query?

using window functions:

select distinct product, brand, first_value(price) on (partition product, brand order ...) latest_price list 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -