我正在尝试创建一个查询,该查询标记属于我与子查询一起提取的贷款号列表中的每个订单项。
到目前为止,我的脚本编写如下:
case when loannumber in
(
select distinct cast(loannumber as float)
from tbl_one
where exists (select a.loannumber,
case when a.FlagA = 0 and b.[NFC] = 'N/A' then 'x'
when a.FlagA = 0 and b.[NFC] <> 'N/A' and sum(a.Amount) > b.[NFC] then 'x'
when a.FlagA = 1 and b.[FC] = 'on approval' then 'x'
when a.FlagA = 1 and b.[FC] <> 'on approval' and sum(a.Amount) > b.[FC]then 'x'
end as [error flag]
from tbl_one a
inner join lkp_table b
on a.State = b.state
group by a.loannumber, FlagA, [NFC], [FC])
)
then 'Error 1' else null end as [Error 1],
当我运行子查询时,它正确地识别了应该被标记的所有贷款号码,但是当我将其放入语句时,它最终会标记人口中的每个贷款号码。有办法解决这个问题吗?