Dinesh G
Dinesh G

Reputation: 1365

How to check two condition in single query in mysql?

Example

------------------------------------------
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'

Output

Credit_Amount = 6000
Debit_Amount = 1250

Here if the type is credit the value should add with credit variable and if type is debit the value should add with debit. Please hep me to solve this Problem.

Upvotes: 1

Views: 93

Answers (1)

PRANAV
PRANAV

Reputation: 629

this is query for credit only you can append as per requirement.

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

Upvotes: 2

Related Questions