PostgreSQL DISTINCT ON与不同的ORDER BY
我想运行此查询:
SELECT DISTINCT ON (address_id) purchases.address_id, purchases.*FROM purchasesWHERE purchases.product_id = 1ORDER BY purchases.purchased_at DESC
但我得到这个错误:
PG ::错误:错误:SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配
添加address_id
为第一个ORDER BY
表达式会使错误无效,但我真的不想添加排序address_id
。是否可以不通过订购address_id
?
浮云间
BIG阳
MMMHUHU
相关分类