如何在查询中添加其他WHERE子句。有此查询:

SELECT round(Sum(Zarada), 2) AS Zarada,
       cms_cart_customers.Firstname,
       cms_cart_wallet.WalletType as WW ,
       cms_cart_customers.Lastname,
       FROM_UNIXTIME(`cms_cart_customers`.`d_ins`, " %d.%m.%Y") AS Datum_formatiran
  FROM (cms_cart_customers)
  LEFT JOIN cms_cart_wallet
    ON cms_cart_wallet.IdBuyer =cms_cart_customers.Id
  WHERE `cms_cart_customers`.`IDReferral` = '199' AND
        if(ww = 7) THEN ' cms_cart_wallet.WalletType =7' END IF
  GROUP BY cms_cart_customers.Id


如果将cms_cart_wallet.WalletType选定为Ww,则添加新的附加子句WHERE cms_cart_wallet.WalletType为7。有可能以这种方式做到吗???

最佳答案

您可以通过在左连接中添加一个以上子句来实现此目的,如下所示。

SELECT round(Sum(Zarada), 2) AS Zarada, cms_cart_customers.Firstname,cms_cart_wallet.WalletType as WW ,cms_cart_customers.Lastname, FROM_UNIXTIME(cms_cart_customers.d_ins, " %d.%m.%Y") AS Datum_formatiran FROM (cms_cart_customers) LEFT JOIN cms_cart_wallet ON cms_cart_wallet.IdBuyer =cms_cart_customers.Id and cms_cart_wallet.WalletType =7 WHERE cms_cart_customers.IDReferral = '199'  GROUP BY cms_cart_customers.Id

关于mysql - MySQL if语句与where子句一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34451640/

10-13 00:03