我目前正在使用这些SQL语句。我的表格有一个名为CPaymentType的字段,其中包含“现金”或“支票”。我可以通过执行2个SQL语句来总结付款金额,如下所示。在这种情况下,当执行2个SQL语句或只执行1个时,用户甚至不会注意到速度差异,但是我不喜欢我的方式,我只想要1个SQL语句。如何使用CASE条件将它们重构为1个语句?我无法弄清楚,因为在线示例的结果要么是1或0或布尔值。我不想包括预日期支票付款。非常感谢。
Select SUM(CAmount) as PaymentAmount
from TableOrderPayment
where CPaymentType='Cash' and CStatus='Active';
Select SUM(CAmount) as PaymentAmount
from TableOrderPayment
where CPaymentType='Check' and CDate<=SYSDATETIME() and CStatus='Active';