MySQL Forums
Forum List  »  Stored Procedures

Case Statement Bug/Syntax error
Posted by: maitrik panchal
Date: February 17, 2012 03:44AM

I've a table like this.

accode amount crdr
--------------------
RUCHTE 63730 D
RUCHTE 79348 D
RUCHTE 127036 C
RUCHTE 158801 C

Here first column is Account Code, second is Amount and third stores that whether amount was Debit or Credit.
I want sum of total Debit amounts and Credit Amounts in one row so,
Now when I fire this query on this table, I am not getting appropriate output.

select
accode,
case when crdr = 'D' then sum(amnt) end `amntd`,
case when crdr = 'C' then sum(amnt) end `amntc`
from tablename
group by accode


current output:
accode amntd amntc
---------------------
RUCHTE 428915 0

required output:
accode amntd amntc
---------------------
RUCHTE 143078 285837

Options: ReplyQuote


Subject
Views
Written By
Posted
Case Statement Bug/Syntax error
2281
February 17, 2012 03:44AM
995
February 17, 2012 10:42AM
1145
February 19, 2012 08:46PM
871
February 20, 2012 11:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.