Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle SQL按表达式排序_Sql_Database_Oracle - Fatal编程技术网

Oracle SQL按表达式排序

Oracle SQL按表达式排序,sql,database,oracle,Sql,Database,Oracle,我正试图通过表达式对某些内容进行排序,但出于某种原因,除非将该表达式作为选择项,否则它将不起作用: select distinct p.stuff from p.places join otherPLACE order by cos(sin(to_number(p.nr_matricol))); 但我总是犯这个错误 ORA-01791:不是选定的表达式 如果我这样写的话 select distinct p.stuff, cos(sin(to_

我正试图通过表达式对某些内容进行排序,但出于某种原因,除非将该表达式作为选择项,否则它将不起作用:

    select distinct p.stuff
    from p.places 
    join otherPLACE
    order by cos(sin(to_number(p.nr_matricol)));
但我总是犯这个错误

ORA-01791:不是选定的表达式

如果我这样写的话

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;

注意:我希望您的代码是伪代码。因为您使用的是笛卡尔连接,除非您指定了列,否则您可以换行到内联视图中

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;
注意:我希望您的代码是伪代码。由于使用笛卡尔连接,除非指定列,否则问题在于排序依据发生在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))));
问题在于,ORDERBY发生在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))));
DBMS不知道您引用的是什么nr_矩阵,因为您使用DISTINCT聚合了行,每个原始行都有自己的nr_矩阵。但DISTINCT本身往往是一个写得不好的查询的标志。鉴于您仅从地点选择,您需要加入吗?也许一个IN或EXISTS子句会更好,甚至可能会避免您必须用DISTINCT消除的重复。类似的方法可能会起作用:选择*从p位置,其中p.x在选择op.y从otherplace op order by。DBMS不知道您引用的是什么nr_矩阵,因为您使用DISTINCT聚合了行,每个原始行都有自己的nr_矩阵。但DISTINCT本身往往是一个写得不好的查询的标志。鉴于您仅从地点选择,您需要加入吗?也许一个IN或EXISTS子句会更好,甚至可能会避免您必须用DISTINCT消除的重复。类似的方法可能会起作用:选择*从p位置,其中p.x在选择op.y从otherplace op order by。