红框部分有问题,删掉后可以正常跑出结果,不知道哪里错了改成t5也不行。。。selecta.,krm.fd_number,fd_heTongHao,,,,,,,,,,,,iif( = '0','否',iif( = '1','是','')) 特惠,t.总金额,iif((select ()-(select (getdate())))<=0,'已到期',iif((select ())-(select (getdate()))<=30 ,'即将到期','')) 合同到期提醒,t5.状态from . a inner join km_review_main krm on a.fd_id = krm.fd_idleft join (select ,sum() 总金额from . a inner join . krm on a.fd_id = krm.fd_idleft join as b on a. = b.left join(select t0.* from(select qwe.fd_number 单号,abc. 状态from (select fd_number,,fd_create_time from a inner join km_review_main krm on a.fd_process_id = krm.fd_id where fd_number like '%KHHT%' ) abc right join(select fd_number,max(fd_create_time) 时间 from a inner join km_review_main krm on a.fd_process_id = krm.fd_id where fd_number like '%KHHT%' GROUP BY fd_number) qweon abc.fd_number = qwe.fd_number and abc.fd_create_time = qwe.时间) t0) t5 on t5.单号 = krm.fd_numberwhere not in ('10','00') and is not nullgroup by ) t on t. = fd_numberwhere not in ('10','00')