首页 > 解决方案 > 使用 LIMIT 函数是子查询

问题描述

我正在使用这个查询:

select city, length(city) 
from station 
where length(city) = (select max(length(city)) from station ) 
   OR length(city) = (select min(length(city)) from station) 
order by city asc;

当我将 LIMIT 函数添加到我的子查询时,因为我只需要该选择的一个结果:

select city, length(city) 
from station 
where length(city) = (select max(length(city)) from station limit 1) 
   OR length(city) = (select min(length(city)) from station limit 1) 
order by city asc;

然后我得到了错误-

ORA-00907: missing right parenthesis 

任何知道我在哪里犯错的人。我使用 Oracle,我尝试使用 rownum 但没有帮助。

标签: sqloraclelimit

解决方案


当您使用max()thenlimit时不需要:

select city, length(city) 
from station 
where length(city) = (select max(length(city)) 
                      from station
                     ) OR 
      length(city) = (select min(length(city)) 
                      from station 
                     ) 
order by city asc;

但是,limit将不支持Oracle.


推荐阅读