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

解决方案 »

  1.   

    最后那个) sda多出来了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
                         ) 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
     
      

  2.   


    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
    --有没有发现你少了什么
      

  3.   


    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这里都是对的,但是多套一层就不对了。
      

  4.   

    --MSSQL的括号只能用来括住数据集 而不能用来括住一个表
    --例如
    select * from (ta )a  --报错
    select * from (select * from ta)a --正确