gpt4 book ai didi

mysql - where 子句中的 SQL if 语句

转载 作者:行者123 更新时间:2023-11-29 23:24:52 25 4
gpt4 key购买 nike

如何在我的声明中添加底线?

SELECT
AgentID,
PaymentAmount
FROM Table A

WHERE
DATEOFPAYMENT

GROUP BY
CollectorNumber

ORDER BY
CollectorNumber,
LastName,
DateofPayment,
PaymentAmount
<小时/>

if DATEOFPAYMENT = yesterday then PaymentAmount else 0 as 'previous day'

if DATEOFPAYMENT = current_Month then PaymentAmount else 0 as 'MTD'

if DATEOFPAYMENT = current_Year then PaymentAmount else 0 as 'YTD

最佳答案

我们可以研究CASE syntax from here , it would be, roughly (I am not acquainted with MySQL date formats , so please look that up )

SELECT AgentID, PaymentAmount FROM Table A

WHERE CASE DATEOFPAYMENT
WHEN subdate(currentDate, 1) THEN PaymentAmount
WHEN month() THEN PaymentAmount
WHEN year() THEN PaymentAmount
ELSE 0
END

GROUP BY CollectorNumber

ORDER BY CollectorNumber, LastName, DateofPayment,
PaymentAmount

这是即将完成的伪代码,因此请修复语法。但case语句是这样的。

关于mysql - where 子句中的 SQL if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27047431/

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