我有查詢:查詢 - 按返回重複行一列此查詢
SELECT DISTINCT
"id",
"fn" || ' ' || "ln" || '/' || "bi" || '('|| TRUNC((months_between(sysdate, "bi") /12)) || ')/' || "pol" || '/ ' || "pol2" AS "INFO",
"cn" ,
"ci",
TO_CHAR("di" , 'DD-MON-YYYY') AS "DIST",
"cif" AS "Cand. Indp." AS "CIF FLAG",
TO_CHAR("ecd", 'DD-MON-YYYY') AS "ECD DATE",
trim(both '/' from ("DSD")) AS "DSD DATE",
trim(both '/' from ("TSD" )) AS "TSD DATE",
"com" AS "COMMENTS",
"SMF" AS "SM Flag"
FROM "MY_TABLE"
ORDER BY "ln";
我得到ORA-01791:不是一個選擇的表達。
我GOOGLE了錯誤和問題似乎是獨特的和順序通過不一起工作。我試圖通過分組而不是明確的並使用max(「ln」),但是對於連接的列,我無法弄清楚如何對它們進行分組。我正在尋找如何對ln上的結果進行排序?
'distinct'更改訂單和'order by'一起工作。您只需要在選擇列表中包含要排序的列。 'MY_TABLE'的主鍵是什麼? –
@a_horse_with_no_name沒有主鍵。這也是一個臨時表。 – user2924127