当我删除子查询时,上述查询有效。但我希望金额乘以查询中指定的表 n_bank_rate 中的名义利率。如何实现?
select 2 as orderby, 2 as n_order2,null as exp_id ,null as company,
'Total -' + fac.facility_type as cashflow,
null as exp_identification_date,
bk.bank_name as bank,null as branch,
null as Counterparty,null as country,null as facility_type,
bank_facility_id as bank_facility_id , null as curr1,
sum(m.amount) as curr1_amt,
null as curr2,
sum(m.amount * (select top 1 notional_rate from n_bank_rate where bank_id = m.bank_id order by id desc)) as curr2_amt,
null as converstion_rate,null as due_date,null as bank_ref,null as invoice_no,null as remarks ,
null as [term],null as [terms_type]
from m_forex_exposure m
join m_company cm on m.comp_id = cm.comp_id
left join m_bank bk on m.bank_id = bk.id
left join m_facility_type fac on m.bank_facility_id = fac.id
join n_link_exposure le on m.exp_id = le.ref_exp_id
where
(cm.comp_main_id = 1 and cm.group_id =1 )
and m.amount > 0
and (m.bank_id =94)
and isnull(m.bank_id,0) <> 0
and bank_facility_id in (select id as bank_facility_id from m_facility_type where facility_type in ('EBRD','PCFC'))
group by bk.bank_name , bank_facility_id,fac.facility_type