Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



Some sql queries for facing Job interviews.


Posted Date: 02 Jul 2008    Resource Type: Articles/Knowledge Sharing    Category: Jobs & Interviews

Posted By: Gitolekha       Member Level: Gold
Rating:     Points: 3



Q1.Table Structure: EMPLOYEE(EmpName, DeptName, Salary)
1. Write a SQL query to get highest salary in each Department.
2. Write a sql to get the number of employees in each Department.
3. Write a sql to split employee in two columns:
a) Employee above 5000(employee getting salary more than 5000)
b) Employee below 5000(employee getting salary below 5000)
No need to show the employee getting salary = 5000

A.
1. SELECT DeptName, MAX(salary) as "Highest salary"
FROM employee
GROUP BY DeptName

2. select DeptName, count(EmpName)
from Employee
group by DeptName

3a. select Salary, EmpName,
case when salary < 5000 then
'Less than 5000'
else
'Greater than 5000'
end
from employee

OR, alternative way,

3a. select case when salary < 5000 then
EmpName+' '+CAST(salary As Varchar(100))
else
NULL
end 'Less than 5000',
case when salary > 5000 then
EmpName+' '+CAST(salary As Varchar(100))
else
NULL
end 'Greater than 5000'
from employee

3b. select EMPNAME = EmpName,
EMPSAL =
case
when salary < 5000
then CAST(Salary as varchar(100))+ ' '+'Less than 5000'
when salary > 5000
then CAST(salary as varchar(100))+' ' +'Greater than 5000'
when salary = 5000
then CAST(salary as varchar(100))+' ' +'Equal to 5000'
end
from employee1


Q2. Write a sql to get the department name having highest number of employees.

A. Select DeptName From Employee1
Group by DeptName
Having count(EmpName) in(
Select Max(A.COUNTEMP)
From (select DeptName, count(EmpName)as COUNTEMP
from Employee1
group by DeptName) A)






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Jobs in ET-Electrotherm (India) Ltd.
Previous Resource: Jobs in Hyundai E & C Co. Ltd., Korea
Return to Discussion Resource Index
Post New Resource
Category: Jobs & Interviews


Post resources and earn money!
 
Related Resources



Watch TV Channels
  • Watch Asianet TV online
  • Kairali TV in Internet
  • Surya TV online
  • Amritha TV Channel

  • Contact Us    Privacy Policy    Terms Of Use   

    SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.