not a Selected expression:不是一个查询表达式;
原始报错sql:
select
distinct
report.fid as "reportId",
-- assign.fassigntype as "type",
report.fsalestatus as "saleStatus",
report.ftransactionstatus as "transactionStatus",
report.fsettleaccountstatus as "settleAccountStatus",
report.ftenementdetail as "tenementDetail",
person.fid as "personId",
person.fname as "personName",
-- 上数业绩,分成比例
(select sum(assign.fprice) || '| ' || sum(assign.fproportion)
from t_trade_commissionassign assign
where report.fid = assign.fktransactionreportid
and assign.fkpersonid = person.fid
) as "ppsum",
to_char(report.ftransactiondate,'yyyy-MM-dd') as "transactionDate"
from t_hr_person person
left join t_trade_commissionassign assign on person.fid=assign.fkpersonid
left join t_trade_transactionreport report on assign.fktransactionreportid=report.fid
where 1=1
and person.fid = '90481a8d-0c05-4002-9532-26e0482a96af'
and to_char(report.ftransactiondate,'yyyy-MM-dd') >= '2017-10-24'
order by report.ftransactiondate desc;
通常ORA-01791--的错误,都是在使用distinct后出现的。
通常是因为distinct和order by 一起使用,因为字段名称冲突报错。
上面的SQL报错是因为order by后使用的字段名称,使用的是原始名称,不是使用别名“transactionDate”所导致的。
也就是说,如果有distinct时,order by后面跟的字段名称,必须是最新的别名(若没有别名,就使用原来的名称,若有多层子查询,则使用最新的那个别名);
上面错误修改:
order by report.ftransactiondate desc;
改为
order by "transactionDate" desc;