i have one table with accounts and amounts as
colums.accounts with columns c and d. and amounts with
values 1000,2000,3000 for c and 4000,5000,8000 for d.i need
to find the sum of these accounts c and d individually
and find the differences between their sum using one select
statement.

Answers were Sorted based on User's Feedback



i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / bunty

Hi,
I dont know if this is a intended way for which interviewer
has asked, but it will definitely give an answer,

select (select sum(value) from test_tab where parent='D')-
(select sum(value) from test_tab where parent='C')
difference from dual;

Cheers,
Bunty

Is This Answer Correct ?    13 Yes 2 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / biswaranjan

this works good for the query


select (select sum(a.amount) from one a where
a.account='d')-(select sum(b.amount) from one b where
b.account='c') from dual;

Is This Answer Correct ?    11 Yes 1 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / apurba

SELECT SUM(C)-SUM(D) FROM TABLE_NAME;

Is This Answer Correct ?    8 Yes 6 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / anuj shukla

Hi all,
question simply ask for the total of both the columns and
their difference, all in one 'select' statement.

select sum(c)"Sum of C",sum(d)"Sum Of
D",abs(sum(c)-sum(d))"Difference" from accountA

Is This Answer Correct ?    4 Yes 2 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / lalitha

SELECT ABS(SUM(DECODE(ACCOUNTS,'C',AMOUNTS))-SUM(DECODE
(ACCOUNTS,'D',AMOUNTS))) FROM TEMP

Is This Answer Correct ?    2 Yes 2 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / akki julak

SELECT SUM(C),SUM(D),SUM(C)-SUM(D) 'difference'
FROM accounts;

Is This Answer Correct ?    3 Yes 3 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / priya

The question is not in proper grammar .. To me it looks like
what Biswaranjan interprets above

Is This Answer Correct ?    0 Yes 1 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / umesh naik

select a.amt1 c_sum ,b.amt2 d_sum
, a.amt1 - b.amt2 cd_diffrence
from
(select sum(amount) amt1 from one_table where account='c')
a,
(select sum(amount) amt2 from one_table where account='c') b












select (select sum(a.amount) from one a where
a.account='d')-(select sum(b.amount) from one b where
b.account='c') from dual;

Is This Answer Correct ?    0 Yes 1 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / vijay sinha

select (select sum(amount) from table_name where account = 'C') - (select sum(amount) from table_name where account = 'D')

Is This Answer Correct ?    0 Yes 1 No

i have one table with accounts and amounts as colums.accounts with columns c and d. and amounts wit..

Answer / ankur maheshwari

select abs(sum(c1.amounts)-sum(d1.amounts)) 'Amount
difference' from account c1, account d1 where
c1.accounts='c' and d1.accounts='d'

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More SQL PLSQL Interview Questions

ex: take one schema in that t1,t2,.....tn tables and you don't no the table name also. write a procedure if enter columns name then display the maching columns .otherwise display the unmatch columns.

1 Answers   Zensar,


Can we join same table in sql?

0 Answers  


How to execute multiple sql statements in a single annonymous block irrespective of the sql statement result?

2 Answers  


how to see the create table statement of an existing table? : Sql dba

0 Answers  


declare l1 number := null; l2 number :=null; begin if l1=l2 then message('equal'); else if l1<>l2 then message('not equal'); else message('else'); end if; end if; end; What will be the output ?

7 Answers   Oracle,






Is it possible to access the current value in a session before accessing next value?

1 Answers  


How to return multiple rows from the stored procedure?

0 Answers  


Can i possible to see Table Details ? Ex : Table Name Date Time User Emp May/18/2010 12:59pm Scott

3 Answers  


What is mutating table?

11 Answers   Saama Tech,


what is the difference between implicit conversions and explicit conversions?

2 Answers  


What is indexing in sql and its types?

0 Answers  


Delete duplicate records in the emp table.

6 Answers   Oracle,


Categories