繁体   English   中英

如何在mysql中的单个查询中检查两个条件?

[英]How to check two condition in single query in mysql?

------------------------------------------
Amount     |   Type
------------------------------------------
1000       | credit
------------------------------------------
4500       | credit
------------------------------------------
1250       | debit
------------------------------------------
500        |  credit
------------------------------------------


select IFNULL(SUM(amount),0) as Credit_Amount,IFNULL(SUM(amount),0) as Debit_Amount, 
type,party from receipt where  party='$list[id]' and type='credit' or 
type='debit'

产量

Credit_Amount = 6000
Debit_Amount = 1250

在这里,如果类型是credit,则值应与credit变量相加;如果type是debit,则值应与debit相加。 请帮助我解决这个问题。

这是信用查询,您只能根据要求附加。

Select IF(type='Credit', SUM(amount), null) as Credit from receipt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM