A table consists of 10 employees how to find sum of 3,4,5,6 employees?

Showing Answers 1 - 17 of 17 Answers

Fazlur Rahiman

  • Jul 25th, 2006
 

What is the meaning of 3,4,5,6? Is Record no or Employee No?

What is the Sum of field name?

  Was this answer useful?  Yes

sivareddy

  • Aug 5th, 2006
 

select * from emp  where rowid in(

             select* from emp where rowid <=6

minus

select * from emp where rowid=3);

  Was this answer useful?  Yes

madhavi.p

  • Sep 1st, 2006
 

The previous person mentioned that one it won't work,try with this it will give the correct result,why means that rowid is returning so many values

select sum(sal) from emp  where  rowid in
 ( select rowid from emp where rownum <= 6 minus select rowid from emp where rownum <=3 );

  Was this answer useful?  Yes

Suneel

  • Sep 9th, 2006
 

This should also work

select sum(sal) from emp  where  rowid between 3 and 6;

  Was this answer useful?  Yes

Sachin

  • Sep 27th, 2006
 

Hi,

Madhavi is absolutely right..

select sum(sal) from emp  where  rowid in
 ( select rowid from emp where rownum <= 6 minus select rowid from emp where rownum <=3 );

It will work fine..

-regards

  Was this answer useful?  Yes

Sachin

  • Sep 27th, 2006
 

Madhavi,

It seems that the query you are firing is taking 3,4,5,6 as rownum,then why can't we go straight as below..

select sum(sal) from emp where rownum in ('3','4','5','6');

You are fetching the rowid first with the help of rownum as 3,4,5,6.

Please correct me if I am wrong!!

-Regards

  Was this answer useful?  Yes

Athar

  • Oct 14th, 2006
 

The query need to be modified as below

1. select sum(sal) from emp  where  rowid in
  ( select rowid from emp where rownum <= 6 minus select rowid from emp where rownum <=2 );

2. rownum cannot be used for evaluating group functions. Oralce returns NULL value for the below query

select sum(sal) from emp where rownum in (3,4,5,6);

or

select sum(sal) from emp where rownum in ('3','4','5','6');

In fact, rownum is numeric value. So, it must not be enclosed in quotes.

  Was this answer useful?  Yes

ajitmelepat

  • Feb 10th, 2007
 

hello, try this one it'll also workselect sum(sal) from (select a,rownum rw from emp)where rw between 3 and 6 ;

  Was this answer useful?  Yes

maddy

  • Jul 31st, 2007
 

SELECT sum(esal) FROM ( SELECT a.*, ROWNUM r FROM EMPmanoj a) WHERE r BETWEEN 2 AND 3

  Was this answer useful?  Yes

If it is employee no and employee no is unique the SQL is below

Select sum(column_name) from Table_name where rownum=>3 and rownum<=6 and Order by employee_number.

  Was this answer useful?  Yes

alekhya

  • Aug 6th, 2012
 

rownum always starts with 1

  Was this answer useful?  Yes

alekhya

  • Aug 6th, 2012
 

SELECT SUM(SAL) FROM (SELECT ROWNUM R,EMPNO,ENAME,sal FROM EMP)
where r in (3,4,5,6)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions