[英]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.