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

.net - Bulk insert via Dapper is slower than inserting rows one-by-one -

shared memory - gstreamer shmsrc and shmsink with h264 data -

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