如何在sum函数中创建if else语句

时间:2019-07-09 13:40:54

标签: mysql reactjs express

我正在尝试求和,但如果要在其中求和,

我尝试了case,它在我的管理员localhost php中工作,但是在服务器节点mariadb上运行时却无法工作

所以我正在尝试else if语句,但语法却出错了

SELECT 
SUM(
   IF(i.currencyID = ${defCurrency} , invD.unitPrice * invD.quantity, 0) 
   ELSE(invD.unitPrice * invD.quantity * 
         (
          SELECT rate 
           FROM currencyRate
           WHERE defaultCurrencyID = ${defCurrency}
           AND currencyID = i.currencyID
         ) as purchasePrice,
    FROM Invoice i, invoiceDetails invD, materialUnit mu
    WHERE mu.materialUnitID = invD.materialUnitID
    GROUP BY mu.materialUnitID

0 个答案:

没有答案