Display the total debit counts, total credit counts, sum of
total debits, sum of total credits from an employee's
transaction table (a single table) containing the following
columns.
Transaction_number
Transaction_amount
Transaction_date
Transaction_type --> tells if the amount is a credit or a
debit.

As the query alone is important, the table is left with
specifying just the field's name. Pls help me with this
query.

Answers were Sorted based on User's Feedback



Display the total debit counts, total credit counts, sum of total debits, sum of total credits fro..

Answer / deepak mohanty

SELECT SUM(decode(txn_typ,'D',1)) "Total Debit
Count",SUM(decode(txn_typ,'C',1)) "Total Credit Count",
SUM(decode(txn_typ,'D',txn_amt)) "Total Debit
Amount",SUM(decode(txn_typ,'C',txn_amt)) "Total Credit Amount"
from txn_tab

Is This Answer Correct ?    13 Yes 2 No

Display the total debit counts, total credit counts, sum of total debits, sum of total credits fro..

Answer / apoorva garg

select count(decode(trim(transaction_type),'D',1)) total_debits,
count(decode(trim(transaction_type),'C',1)) total_credits,
sum(decode(trim(transaction_type),'D',transaction_amount)) total_debits_amt,
sum(decode(trim(transaction_type),'C',transaction_amount)) total_credits_amt
from transaction

Is This Answer Correct ?    3 Yes 0 No

Display the total debit counts, total credit counts, sum of total debits, sum of total credits fro..

Answer / ajit

Also u can use count function to calculate total debit & credit cout.
and u can use this sql stmt

select tran_type, Count(tran_type) total,
(select sum(tran_amt)
from tran
where tran_type = 'D') sumofde,
(select sum(tran_amt)
from tran
where tran_type = 'C') sumofce
from tran
group by tran_type;

Is This Answer Correct ?    0 Yes 10 No

Post New Answer

More SQL PLSQL Interview Questions

What is a schema? How is it useful in sql servers?

0 Answers  


Is pl sql different from sql?

0 Answers  


Why do we need cursors in pl sql?

0 Answers  


What jobs use sql?

0 Answers  


How you improve the performance of sql*loader? : aql loader

0 Answers  






Can you have multiple SPs with the same name on a database?

2 Answers   CGI, Quest,


How do you get all records from 2 tables. Which join do you use?

8 Answers   Microsoft,


Explain the usage of WHERE CURRENT OF clause in cursors ?

4 Answers   Satyam,


What is the difference between having and a where in sql?

0 Answers  


First round ------------------- - Procedure - Packages - Views - Virtual tables - Can we use dcl with in function? - Joins and few scenarios - Triggers and its type - Pragma, type and its functionality - How to create db link in oracle - Materialized view - How to find duplicate values from table? - Cursor and its functionality - Write a script to display friday and its date from a entire year. - Exception Handling Second round ------------------------ Gave a scenario like. Need to write a function to perform. When user try to change a password. It must not be last five password and a given password can be combination of characters, symbols, upper and lower case.

0 Answers   Prodapt,


What are the built in functions of sql?

0 Answers  


What is a merge query?

1 Answers  


Categories