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

Can we use update in sql function?

589


what is the difference between group by and order by in sql? : Sql dba

600


How does a self join work?

522


How do I find duplicates in two columns?

557


How can we avoid duplicating records in a query?

568






what are the advantages of sql ? : Sql dba

552


How to write pl sql program in mysql command prompt?

521


How do I view a table in sql?

547


Is full outer join same as cross join?

505


What are all types of user defined functions?

532


How does rowid help in running a query faster?

970


Can a varchar be a primary key?

540


How to get each name only once from an employee table?

614


What is difference between joins and union?

535


What is the difference between explicit and implicit cursors in oracle?

518