需求:客户做代客结汇交易时“当日期初+当日代客结汇-当日代客售汇+当日买入-当日卖出+当前代客结汇交易金额>敞口限额”则提示用户先去平盘
后台sql为:
from (
select sum(f.mamount) buybalance
from FE_TRANSFOREIGNEXCHANGE f
where f.nofficeid = 1
and f.ncurrencyid = 2
and f.ntranstypeid in(1101)
and f.nstatusid >= 2
and f.dtexecutedate >= to_date('2011-09-06','yyyy-mm-dd')
and f.dtexecutedate <= to_date('2011-09-06','yyyy-mm-dd')
)t2,
(select sum(f.mamount) salebalance
from FE_TRANSFOREIGNEXCHANGE f
where f.nofficeid = 1
and f.ncurrencyid = 2
and f.ntranstypeid in (1102)
and f.nstatusid >= 2
and f.dtexecutedate >= to_date('2011-09-06','yyyy-mm-dd')
and f.dtexecutedate <= to_date('2011-09-06','yyyy-mm-dd')
)t3,
(select sum(fe.mfamount) inbalance
from fe_foreignbalance fe
where fe.nofficeid = 1
and fe.ncurrencyid = 2
and fe.ndirection = 2
and fe.nstatusid >= 2
and fe.ntranstypeid = 1105
and fe.dtexecutedate >= to_date('2011-09-06','yyyy-mm-dd')
and fe.dtexecutedate <= to_date('2011-09-06','yyyy-mm-dd')
)t4,
(select sum(fe.mfamount) outbalance
from fe_foreignbalance fe
where fe.nofficeid = 1
and fe.ncurrencyid = 2
and fe.ndirection = 1
and fe.nstatusid >= 2
and fe.ntranstypeid = 1105
and fe.dtexecutedate >= to_date('2011-09-06','yyyy-mm-dd')
and fe.dtexecutedate <= to_date('2011-09-06','yyyy-mm-dd')
)t5,
(select fi.exposurelimit
from fi_integratedposition fi
where fi.ncurrencyid = 2
and fi.nstatusid = 1
and fi.nofficeid = 1
)t6;