select * from ((select * from (select distinct b.CustomNm,b.CIFNm,b.ApproveNm,b.loannm, b.LoanAmount,a.LoanBalance,b.LoanPerid,
b.LoanStratDate,b.LoanEndDate,b.ComyLoanPurpose from InterestReceive a right join OPSInf b on a.ContractNm=b.LoanNm) aajoin
---连接客户类型
(select distinct * from (select a.LoanAccount,a.LoanNm,case b.LoanType
when '个人客户' then b.PerType
when '企业客户' then b.ComyCustomType
else '' end tp
from
OPSInf a left join LoanInf b on a.CIFNm=b.CIFNm) cc ) dd
on aa.LoanNm =dd.LoanNm) bc) sda
b.LoanStratDate,b.LoanEndDate,b.ComyLoanPurpose from InterestReceive a right join OPSInf b on a.ContractNm=b.LoanNm) aajoin
---连接客户类型
(select distinct * from (select a.LoanAccount,a.LoanNm,case b.LoanType
when '个人客户' then b.PerType
when '企业客户' then b.ComyCustomType
else '' end tp
from
OPSInf a left join LoanInf b on a.CIFNm=b.CIFNm) cc ) dd
on aa.LoanNm =dd.LoanNm) bc) sda
FROM ( SELECT *
FROM ( SELECT DISTINCT
b.CustomNm ,
b.CIFNm ,
b.ApproveNm ,
b.loannm ,
b.LoanAmount ,
a.LoanBalance ,
b.LoanPerid ,
b.LoanStratDate ,
b.LoanEndDate ,
b.ComyLoanPurpose
FROM InterestReceive a
RIGHT JOIN OPSInf b ON a.ContractNm = b.LoanNm
) aa
JOIN ---连接客户类型
( SELECT DISTINCT
*
FROM ( SELECT a.LoanAccount ,
a.LoanNm ,
CASE b.LoanType
WHEN '个人客户' THEN b.PerType
WHEN '企业客户'
THEN b.ComyCustomType
ELSE ''
END tp
FROM OPSInf a
LEFT JOIN LoanInf b ON a.CIFNm = b.CIFNm
) cc
) dd ON aa.LoanNm = dd.LoanNm
) bc
select * from
(select * from (select distinct b.CustomNm,b.CIFNm,b.ApproveNm,b.loannm, b.LoanAmount,a.LoanBalance,b.LoanPerid,
b.LoanStratDate,b.LoanEndDate,b.ComyLoanPurpose from InterestReceive a right join OPSInf b on a.ContractNm=b.LoanNm) aajoin
---连接客户类型
(select distinct * from (select a.LoanAccount,a.LoanNm,case b.LoanType
when '个人客户' then b.PerType
when '企业客户' then b.ComyCustomType
else '' end tp
from
OPSInf a left join LoanInf b on a.CIFNm=b.CIFNm) cc ) dd
on aa.LoanNm =dd.LoanNm) bc
或者select * from (select * from(select * from (select distinct b.CustomNm,b.CIFNm,b.ApproveNm,b.loannm, b.LoanAmount,a.LoanBalance,b.LoanPerid,
b.LoanStratDate,b.LoanEndDate,b.ComyLoanPurpose from InterestReceive a right join OPSInf b on a.ContractNm=b.LoanNm) aajoin
---连接客户类型
(select distinct * from (select a.LoanAccount,a.LoanNm,case b.LoanType
when '个人客户' then b.PerType
when '企业客户' then b.ComyCustomType
else '' end tp
from
OPSInf a left join LoanInf b on a.CIFNm=b.CIFNm) cc ) dd
on aa.LoanNm =dd.LoanNm) bc) sda
--有没有发现你少了什么
select * from (select distinct b.CustomNm,b.CIFNm,b.ApproveNm,b.loannm, b.LoanAmount,a.LoanBalance,b.LoanPerid,
b.LoanStratDate,b.LoanEndDate,b.ComyLoanPurpose from InterestReceive a right join OPSInf b on a.ContractNm=b.LoanNm) aajoin
---连接客户类型
(select distinct * from (select a.LoanAccount,a.LoanNm,case b.LoanType
when '个人客户' then b.PerType
when '企业客户' then b.ComyCustomType
else '' end tp
from
OPSInf a left join LoanInf b on a.CIFNm=b.CIFNm) cc ) dd
on aa.LoanNm =dd.LoanNm这里都是对的,但是多套一层就不对了。
--例如
select * from (ta )a --报错
select * from (select * from ta)a --正确