日期:2014-05-17  浏览次数:20882 次

ORA-01427: 单行子查询返回多个行 求解
SQL code
select * from (select rownum n,B.* from (select X.xybh,X.xymc, (select count(distinct XJ.kcdm) from xjkcwzb XJ where 1=1 and XJ.xyjsxxb_id in (select yhb_id from yhb) and XJ.kcdm in(select k.kcdm from kcdmb k) and (select K.xybh from kcdmb K where XJ.kcdm=K.kcdm)=X.xybh group by X.xybh) as xyjssl,(select count(distinct KC.kcdm) from kcdmb KC where KC.sfty=0 and KC.xybh=X.xybh group by X.xybh) as xykczs,((select count(distinct KC.kcdm) from kcdmb KC where KC.sfty=0 and KC.xybh=X.xybh group by X.xybh)-(select count(distinct XJ.kcdm) from xjkcwzb XJ where 1=1 and XJ.xyjsxxb_id in (select yhb_id from yhb) and XJ.kcdm in (select k.kcdm from kcdmb k ) and (select K.xybh from kcdmb K where XJ.kcdm=K.kcdm)=X.xybh group by X.xybh)) as xylszs,trunc((((select count(distinct XJ.kcdm) from xjkcwzb XJ where 1=1 and XJ.xyjsxxb_id in (select yhb_id from yhb) and XJ.kcdm in(select k.kcdm from kcdmb k ) and (select K.xybh from kcdmb K where XJ.kcdm=K.kcdm)=X.xybh group by X.xybh)/(select (case when count(distinct KC.kcdm)=0 then 1 else count(distinct KC.kcdm) end) from kcdmb KC where KC.sfty=0 and KC.xybh=X.xybh group by X.xybh ))*100),2) as xyjsqk from dual,xyxxb X order by to_number(X.xybh)) B )A where A.n between 1 and 20

公司高人写的SQL,但是报错,求指出错误地方……我实在是看不出来了……

------解决方案--------------------
你的SQL语句都化的了。。

你检查下这里 :

trunc((((select count(distinct XJ.kcdm)
from xjkcwzb XJ
where 1 = 1
and XJ.xyjsxxb_id in
(select yhb_id from yhb)
and XJ.kcdm in (select k.kcdm from kcdmb k)
and (select K.xybh
from kcdmb K
where XJ.kcdm = K.kcdm) = X.xybh