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

Is sql low level language?

0 Answers  


Can you have a foreign key without a primary key?

0 Answers  


How to start the command-line sql*plus?

0 Answers  


How do you use a while loop in pl sql?

0 Answers  


Differentiate between %type and %rowtype attribute in Oracle PL/AQL programming ?

7 Answers   PreVator,






what is the use of friend function? : Sql dba

0 Answers  


how do you know if your mysql server is alive? : Sql dba

0 Answers  


What is union and union all keyword in sql?

0 Answers  


I have a package in which a table was used in a procedure and compiled later i have dropped the table used in the package what would be the status of package specification and body

1 Answers   TCS,


I have one Excel file with 1,50,000 Records. Now I need to load that whole file into Oracle Database with same columns in Excel sheet . I need PLSQL Procedure or used by SQL PLUS

7 Answers   Polaris,


What is pl/sql and what is it used for?

4 Answers  


What is java sql connection?

0 Answers  


Categories