adspace


trans_id trans_date trans_amt debit_credit_indicator
001 01-JAN-13 1099 cr
001 12-JAN-13 500 db
002 24-FEB-13 400 db
002 23-MAR-13 345 cr
001 18-APR-13 800 cr
002 15-MAR-13 600 db
001 12-FEB-13 200 cr

i want like this output
trans_id trans_date trans_amt debit_credit_indicator
001 JAN 1599 cr

no.of trans
2

i want trans_id and trans_date like 'JAN' or 'FEB' etc,
trans_amt i want all credit amount - debit amount per each
trans_id. and debit_credit_indicator and no.of transactions
in a month.

Answer Posted / vinay

Select distinct trans_id ,
to_char(trans_date,'MON') as TRANS_DATE,
count(trans_amt) over (partition by trans_id,to_char
(trans_date,'MON')) as No_OF_TRANSACTION
,sum(trans_amt) over (partition by trans_id,to_char
(trans_date,'MON')) as TRANS_AMOUNT,
debit_credit_indicator from CUSTOMER

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the best sql course?

1064


what is collation? : Sql dba

1242


Does group by remove duplicates?

1121


what is schema? : Sql dba

1163


what is bcp? When does it used? : Sql dba

1065


What is your daily office routine?

2353


how to escape special characters in sql statements? : Sql dba

1124


how to start mysql server? : Sql dba

1279


how many tables will create when we create table, what are they? : Sql dba

1156


what is sql server agent? : Sql dba

1189


What is the current version of sql?

1106


What is the current version of postgresql?

1188


Can delete statement be rollbacked?

1065


what is dbms? : Sql dba

1070


If a cursor is open, how can we find in a pl/sql block?

1252