[英]Oracle SQL order by expresion
我正在尝试通过表达式对某事进行排序,由于某种原因,除非我将该表达式作为选择,否则它将无法工作:
select distinct p.stuff
from p.places
join otherPLACE
order by cos(sin(to_number(p.nr_matricol)));
但我不断收到这个错误
ORA-01791:不是SELECTED表达式
如果我这样写
select distinct
p.stuff,
cos(sin(to_number(p.nr_matricol)))
from p.places
join otherPLACE
order by cos(sin(to_number(p.nr_matricol)));
它可以工作,但我不想打印该列。
有什么办法可以使我工作吗?
您可以包装到嵌入式视图中
SELECT a FROM
(select distinct p.stuff a, cos(sin(to_number(p.nr_matricol))) b
from p.places
join otherPLACE) T
ORDER BY b;
注意:我希望您的代码是伪代码。 因为您要进行笛卡尔连接,除非您指定列
问题在于, order by
是在select distinct
之后发生的。 唯一可用的值是select
。 一种典型的方法是聚合。
像这样:
select p.stuff
from places p join
otherPLACE op
on . . .
group by p.stuff
order by cos(sin(to_number(max(p.nr_matricol))));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.