我有查询:
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:不是选定的表达式。
我用谷歌搜索错误,问题似乎是不同的和顺序不一起工作。我尝试分组而不是使用max(“ln”),但是使用连接列我无法弄清楚如何对它们进行分组。我基本上看是如何在ln上对结果进行排序的?
答案 0 :(得分:1)
您不是通过ORDER BY“ln”
选择的您只能按所选列选择或添加选择
SELECT DISTINCT
"id",
"fn" || ' ' || "ln" || '/' || "bi" || '('|| TRUNC((months_between(sysdate, "bi") /12)) || ')/' || "pol" || '/ ' || "pol2" AS "INFO",
"ln",
"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";
或按
更改订单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 2;