Tippical Interview Querries

Posted by Venu510 under Others on 7/4/2011 | Points: 10 | Views : 1061 | Status : [Member] | Replies : 3
HI Friends!

Can any one give me the tippical interview querries like find the 3rd employee salary with out using top et..c




Thanks & Regards
------------------
Venu




Responses

Posted by: Neha-kapoor on: 7/4/2011 [Member] Starter | Points: 25

Up
0
Down
what you think about yourself and why we offer this job ?


thanks

Venu510, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 7/4/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
What do mean by 3rd Employee Salary
if the Employee table is something like this
Employee Table
EmployeeName  Salary

ABC 5000
XYZ 5000
PQR 4000
DOT 4000
NET 3000
HELLO 2000

If 3rd Employee Salary means
1. Salary of the Employee who is at stored at postion 3

--- Please note I am not showing EmployeeID of Employee

Select Salary from
(SELECT *,ROW_NUMBER() Over(order by EmpoyeeID) as Position from Employee) as X
Where X.Position=3

2. If it refers to find out the 3rd Highest Salary

You use DENSE_RANK() function or Group By clause with co related sub query to find them out
1. Using Built In Function
Select Salary from

(Select *,DENSE_RANK() Over( order by Salary desc) as SRANK from Employee) as X
where X.SRANK=3

2. Using GroupBy Clause

Select Salary from ( Select EX.* ,
(Select Count(1)+1 from
(Select Salary from Employee E group by E.Salary having E.Salary > EX.Salary) K) SRANK
from Employee EX ) X Where X.SRANK=3


Venu510, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kevinm on: 8/25/2011 [Member] Starter | Points: 25

Up
0
Down
Can you please give more details about the question?

Venu510, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response