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
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 |
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 |
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 |
What is restrict in sql?
what is global variable in package
hi this is nakka i have been looking for 1+ exp in oracle sql,plsql developer positions also have knoledge on d2k i am not getting proper walkins how to know it? where can i find it?
Regarding joins what are the differences you observed in oracle 9i and sql server?
cursor types? explain with example programs?
Authentication mechanisms in Sql Server ?
With out using count() function. How to the find total number of rows in a table?
How to order siblings in oracle hierarchy queries?
What is a dynamic query?
What is before and after trigger?
How do you retrieve set of records from database server. {Set max records = 100 & use paging where pager page no or records = 10 & after displaying 100 records again connect to database retrieve next 100 }
Can we perform dml on view?