gpt4 book ai didi

MySQL if 语句与 where 子句一起使用

转载 作者:行者123 更新时间:2023-11-29 21:41:34 25 4
gpt4 key购买 nike

如何向查询添加附加 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 is 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 if 语句与 where 子句一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34451640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com