首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何运行此类sql查询。我在这里面临一个错误,或01427。

问如何运行此类sql查询。我在这里面临一个错误,或01427。
EN

Stack Overflow用户
提问于 2013-10-07 11:42:30
回答 4查看 272关注 0票数 1

我编写了一个sql查询。

代码语言:javascript
复制
select a.unit_code unit,
       a.gh_vill pl_vill,
       a.gh_grow pl_grow,
      (select gh_area 
         from w_cane_survey_2013 b 
        where b.croptype_code > 12 and a.gh_no = b.gh_no ) as paudha,
      (select gh_area 
         from w_cane_survey_2013 b
        where b.croptype_code < 13 and a.gh_no = b.gh_no) as pedi 
  from w_cane_survey_2013 a 
 where a.unit_code = '03' and a.gh_vill = '9991' and gh_grow = '1';

当我执行它时,我会得到一个错误

ORA-01427:单行子查询返回多行

01427。00000 -“单行子查询返回多行”

*原因:

*行动:

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-10-07 13:04:06

尝试这个查询,我希望它有帮助:

代码语言:javascript
复制
select unit_code as unit,
   gh_vill as pl_vill,
   gh_grow as pl_grow,
   case when croptype_code > 12 then gh_area end as paudha,
   case when croptype_code < 13 then gh_area end as pedi
from 
w_cane_survey_2013 
where 
unit_code = '03' and gh_vill = '9991' and gh_grow = '1' 
Group by
unit_code, gh_vill , gh_grow, croptype_code, gh_area;
票数 1
EN

Stack Overflow用户

发布于 2013-10-07 11:45:06

这是因为子查询返回了多行。在子查询中再添加一个ROWNUM=1条件,然后尝试。

代码语言:javascript
复制
select 
    a.unit_code unit, 
    a.gh_vill pl_vill, 
    a.gh_grow pl_grow, 
    (select gh_area from w_cane_survey_2013 b 
      where b.croptype_code > 12 and a.gh_no = b.gh_no and ROWNUM=1) as paudha, 
    (select gh_area from w_cane_survey_2013 b 
      where b.croptype_code < 13 and a.gh_no = b.gh_no and ROWNUM=1) as pedi 
from 
    w_cane_survey_2013 a 
where 
    a.unit_code = '03' and 
    a.gh_vill = '9991' and 
    gh_grow = '1';
票数 2
EN

Stack Overflow用户

发布于 2013-10-07 11:51:17

可以清楚地看到,您正在获取多个行。请查看您的表或多做您的限制,以便您只能得到一行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19223980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档