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

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -