GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Testing  >  DataBase Testing
Go To First  |  Previous Question  |  Next Question 
 DataBase Testing  |  Question 19 of 50    Print  
Now suppose i have 50 records of employee table.
1) I want to find the person who is having 22nd highest salary.

2)i want to delete a person with postion number 39 with comminsion < 100

3) Update rec no 45

records are not shown.
how do i do it.

  
Total Answers and Comments: 9 Last Update: February 28, 2008     Asked by: Sriharsha 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 12, 2006 06:43:51   #1  
Rajasekhar        

RE: Now suppose i have 50 records of employee table.

Use the below SQL statement

select employee_id first_name last_name from employees a where &n (select count(salary) from employees b where a.salary < b.salary)

Regards

Rajasekhar.N


 
Is this answer useful? Yes | No
June 14, 2006 09:40:37   #2  
Sanjay        

RE: Now suppose i have 50 records of employee table.

select emp_id emp_name sal from employee a where &n (select count(distinct(salary)) from employee b where a.sal < b.sal)

&n 22 ( U will be asked to enter the number and then enter for which record u want to retrieve)

a.sal < b.sal (this can be used to retrieve max record)

a.sal > b.sal( this can be used to retrieve min record)


 
Is this answer useful? Yes | No
August 15, 2006 13:48:14   #3  
jyothi        

RE: Now suppose i have 50 records of employee table.

for 1 question the query is

select level max(sal) from employees

wherelevel &level

connect by prior sal>sal

group by level; here u should mention level as22

2)delete from employees where positionnumber 39andcommision<100;


 
Is this answer useful? Yes | No
October 23, 2006 10:39:44   #4  
Manoj        

RE: Now suppose i have 50 records of employee table.

For the 1st question

Select * from emp where sal (Select * from (select sal from emp order by sal desc) group by sal having rownum 22)


 
Is this answer useful? Yes | No
November 09, 2006 00:01:18   #5  
Parvathi        

RE: Now suppose i have 50 records of employee table.

Hi

For the 1st Question:
Ans:- Select a.sal from emp a where 29 (select count(distinct(b.sal)) from emp b Where a.sal< b.sal)
For the 2nd Question:
Ans:-Delete from Employee where Positionnumber 39 and Commission<100;
For the 3rd Question:
And:-update employee set recno 45;

Thanks

Parvathi.


 
Is this answer useful? Yes | No
November 09, 2006 02:11:30   #6  
Uday Kumar T.V.        

RE: Now suppose i have 50 records of employee table.

To find out the 22nd highest salary

use this query

select * from employee e1

where

(select count(distinct(salary)) from employee e2

where e2.salary>e1.salary) (22-1)

since there must only be 21 salaries above this


 
Is this answer useful? Yes | No
December 02, 2006 01:51:23   #7  
vadivelan        

RE: Now suppose i have 50 records of employee table.

First question:

select min(salary) from (select distinct salary from employee order by salary desc) where rownum< 22);

or

select max(salary) from (select distinct salary from employee order by salary asc) where rownum< 22);

second question:

delete from employee where emp_id 39 and comm<100;

Third question

update table employee set recno 45;


 
Is this answer useful? Yes | No
June 30, 2007 10:52:45   #8  
Jayant Naikwade        

Solution in Oracle
1) I want to find the person who is having 22nd highest salary.


SELECT * FROM (SELECT rownum r A.* FROM
(SELECT
l.* FROM employee l ORDER BY l.empsal DESC) A)

WHERE B.R '4' )

2) I want to delete a person with position
number 39 with commission < 100
DELETE FROM emp WHERE posno 39 and comm < 100


3) Update
record number is 45
UPDATE emp WHERE recno 45


 
Is this answer useful? Yes | No
February 28, 2008 03:43:11   #9  
akavitha Member Since: February 2008   Contribution: 3    

RE: Now suppose i have 50 records of employee table.1) I want to find the person who is having 22nd highest salary.2)i want to delete a person with postion number 39 with comminsion < 1003) Update rec no 45records are not shown.how do i do it.

Ans 1: (works only for db2 for oracle use rownum())

SELECT EMP_NAME SAL FROM (SELECT EMP_NAME SAL ROWNUMBER() OVER (ORDER BY SAL desC) AS RN FROM EMP) A
WHERE
A.RN 22

Ans 2 : Question is not clear.

delete from emp where positionnumber 39 and commission<100;

Ans 3: Update rec no 45

UPDATE EMP SET EMP_NAME 'XYZ'
WHERE
EMP_NAME (SELECT EMP_NAME FROM (SELECT EMP_NAME SAL ROWNUMBER() OVER (ORDER BY EMP_NO ASC) AS RN FROM EMP) A
WHERE
A.RN 45)






 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape