Tag: distinct on

PostgreSQL DISTINCT与不同的ORDER BY

我想运行这个查询: SELECT DISTINCT ON (address_id) purchases.address_id, purchases.* FROM purchases WHERE purchases.product_id = 1 ORDER BY purchases.purchased_at DESC 但是我得到这个错误: PG ::错误:错误:SELECT DISTINCT ONexpression式必须匹配初始的ORDER BYexpression式 添加address_id作为第一ORDER BYexpression式沉默错误,但我真的不希望添加sortingover address_id 。 有没有可能没有通过address_id命令?