我有一个PostgreSQL表。
我可以获得不同的产品和品牌:
SELECT DISTINCT product, brand FROM list
在Django之后,我得到了最新的价格:
查询中的x:
SELECT price FROM list
WHERE product = x.product AND brand = x.brand
ORDER BY ...
LIMIT 1
如何通过一个查询获取所有内容?
答案 0 :(得分:0)
SELECT DISTINCT product, brand, FIRST_VALUE(price) OVER (PARTITION BY product, brand ORDER BY ...) AS latest_price
FROM list