sql - 使用 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 但没有帮助。
解决方案
当您使用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
.
推荐阅读
- batch-file - 批量复制
- jestjs - jest 可以在测试运行中包含快照,但排除对代码覆盖的贡献吗?
- firebase - 通过按后退按钮关闭应用程序时,Flutter Foreground Service 无法正常工作
- java - 区域设置在android studio Emulator中成功更改,在使用应用程序时在实际设备中没有更改
- java - RecyclerView 项目不重复,但保留其插槽中先前项目的更改
- python - 在 PyTorch 中屏蔽损失函数的最合适方法是什么
- javascript - 我有与内容安全政策相关的问题
- python - 来自同一对象的 2 个不同引用对来自同一类的两个不同对象 - DJANGO 数据库
- javascript - Javascript Promise - 带返回值的递归 - “记住层次结构”
- ruby-on-rails - React Rails Dokku Heroku 在生产中提供静态文件