SELECT pl_id,
distinct ON (store.store_ID),
in_user_id
FROM plan1.plan_copy_levl copy1
INNER JOIN plan1._PLAN_STORE store
ON copy1.PLAN_ID = store .PLAN_ID;
在postgres服务器中运行此查询时,我收到以下错误。如何使用distinct子句..上面的代码计划1是架构名称。
错误:语法错误处于或接近“不同”第2行:不同的ON (store.store_ID),
答案 0 :(得分:2)
您缺少order by
,其中第一组行应该是distinct on
子句中指定的行。此外,distinct on
子句应位于选择列表的开头。
试试这个:
SELECT distinct ON (store_ID) store.store_ID, pl_id,
in_user_id
FROM plan1.plan_copy_levl copy1
INNER JOIN plan1._PLAN_STORE store
ON copy1.PLAN_ID = store .PLAN_ID
order by store_ID, pl_id;