我编写了一个sql查询。
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 -“单行子查询返回多行”
*原因:
*行动:
发布于 2013-10-07 13:04:06
尝试这个查询,我希望它有帮助:
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;发布于 2013-10-07 11:45:06
这是因为子查询返回了多行。在子查询中再添加一个ROWNUM=1条件,然后尝试。
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';发布于 2013-10-07 11:51:17
可以清楚地看到,您正在获取多个行。请查看您的表或多做您的限制,以便您只能得到一行。
https://stackoverflow.com/questions/19223980
复制相似问题