Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从表中的两个不同列中获取特定值_Mysql - Fatal编程技术网

Mysql 从表中的两个不同列中获取特定值

Mysql 从表中的两个不同列中获取特定值,mysql,Mysql,我有一个select报表,它将利息支付的总额作为利息总额。下面是我正在使用的sql代码 select sum(round(a.Amount * e.average_rate / f.average_rate, 2)) as earningTotal , sum(d.interest_payment) as interestTotal, sum(d.interest_paid) as NetInterest, a.*, c.symbol, c.Abbreviati

我有一个select报表,它将利息支付的总额作为利息总额。下面是我正在使用的sql代码

select  sum(round(a.Amount * e.average_rate / f.average_rate, 2)) as earningTotal ,
        sum(d.interest_payment) as interestTotal,
        sum(d.interest_paid) as NetInterest,
a.*, c.symbol, c.Abbreviation, d.*
from   investment a
inner join money_offer b
on a.ORIG_ID = b.investment_orig_id and b.UPDATE_DT is null
inner   join payment_plan d 
on d.offer_orig_id = b.ORIG_ID and d.UPDATE_DT is null
inner   join currency c 
    on  d.currency = c.ID 
inner join exchange_rates e 
    on  e.currency_id = a.Currency
inner join exchange_rates f 
    on  f.currency_id = a.Currency
where   a.Owner = 518  and
        a.UPDATE_DT is null;
这是一张显示表格信息的图片。

问题是,现在我只取利息支付并求和,但如果第一次利息支付的利息支付值>0(现在为零),现在为0.08,那么我应该选择第一行的利息支付,并将其与第二行(0.16)+和第三行0.08的利息支付相加。将来可能会有更多的争吵

简单来说,因为所有3行利息都是0,所以这很好,但是如果第一行或第二行利息的值大于0,我需要取这些值,并将其与第三行利息的值相加。我在考虑组建一个工会,但我不知道该怎么办