Sunteți pe pagina 1din 8

SQL QUERIES

1. List all information about the employees in the Emp Table. SELECT * FROM Emp 2. List all information about the Departments in the Dept Table.

SELECT Departments FROM Dept 3. List the employee number, name, Job title and Hiredate of employee in department 10. SELECT . FROM department 10 4. Select the name and salary of all employees who are clerks. SELECT name,salary FROM employees WHERE jobtitle=clerk 5. Select the name and annual salary of all employees. SELECT name,salary FROM employee 6. List the Name,Job, Salary of everyone Hired in December 17,1980. SELECT FROM employee WHERE date= 12/17/1980 7.List the Department Name and Department number for Department with numbers greater than or equal to 20. SELECT dept_name, dept_number FROM depts. WHERE number >20 8.List all employees who have a salary between 1000 and 2000. SELECT * FROM employees WHERE salary>1000 AND salary<2000 (or) salary BETWEEN 1000 AND 2000. 9.List the names of employees where Salaries are less than 2500. SELECT name FROM employees WHERE salary<2500 10.Select the name,salary and commission of employees where commission is greater than their salary. SELECT Ename,salary,commission FROM employees WHERE commission>salary

11.Display the name,monthly salary,daily salary and Hourly salary for employees.Assume that the Sal column in the table is the monthly salary,that there are 22 working days in a month,and that there are 8 working hours in a day.Rename the columns as monthly,daily and hourly. SELECT Ename,salary,-----------------------------12.List the names and employers numbers of managers who earn more than 2600 display in Alphabetic order by name. SELECT Ename,Empno FROM employee WHERE job=manager AND salary>2600 ORDER BY Ename 13.Display all employees names which have TH or LL in them. SELECT Ename where ename like %th% OR %ll% -----------------------14.List the details of the employees in Departments 10 and 20 in alphatical order of Name. SELECT * WHERE deptno =10 OR deptno=20 15.Select the information about manager and the president from the column job in the table emp.Order the result by department number. Select * from emp.order where job=manager or job=president order by deptno 16.List the employee names that donot end with S. Select Ename from employee where ename like !%s--------------------------17.List the employee names that starts with C. Select ename from employee where ename like c% 18.List the name,job and department of everyone whose name falls in the Alphabetic range C To F. Select ename,job,deptno where ename like -----------------------------19.List employees details working in department 20,30 or 40. Select * from employee where deptno in (20,30,40) 20.List of employees whose names start with T and end with R. Select ename from employee where ename like t%r 21.Display all employees who were hired in 1981.

Select ename fomr employee where hiredate=1981 22.Display the data as shown below: Smith has held the position of cljerk in dept 20 since 19 June 83 Allen has held the position of salesman in dept 30 since 19 June 1983. Ward has held the position of salesman in Dept 30 since 19 June 1983. &$$%^$%&*%(*&%#$@@--------------------------------------------------23.List all rows from Emp table, by converting the null values in comm Column to 0. Update employee set commission=0 where commission=null 24.List all managers and salesman with salaries over Rs. 1500/Select * from employee where job in (manager, salesman) and where salary>1500 25.Write a Query that will accept a given job titile and displays all records according to that title. Accept salary Prompt Enter value for salary: Select * from employee where job=clerk 26.List of employees who do not get any commission. 27.Show what length names appears in the emp table.Eliminate, Duplicate lengths from the rows returned.Do not show the names themselves. Select distinct len(ename) as length from employee 28.List the names and hire dates of the employees in Dept 20 Display hire date formatted as 12/03/84. --------------------------------------------should we make a table and update it? 29.How many months has the president worked for the company? Round nearest whole number of months. 30.List the names of all employees whose hire date anniversary is in the month of December. 31.Give SQL command to find the average salary per job in each Dept.This SQL figures in Emp table are for each month. 32.In one Query,count the number of people in Dept. No.30 who can receive a salary and the number of people who receive a commission. 33.Compute the average,minimum and maximum salaries of those groups of employees having

the job clerk or manager. 34.Calculate the total compensation expense for each Dept.for one year,the SQL comm figure in the Emp table are for each month.Assume that employees who donot earn a commission receive non-monetory benefits that are worth $ 100.00 a month. 35.Do a case insensitive search for a list of employees with a job that a user enters (e.g. clerk). 36.Produce the following output Employee Smith(clerk) 37.Which employees earn less than 30% of the Presidents salary. 38.Who was the last employee hired in each department. 39.Create a view consisting of number of employees and their total sum of salary grouped by Dept No.wise. 40.Create a view consisting of all the columns from Emp Table and their corresponding records from Dept.Table consisting of Dname & location. 41.How many employees work in the Newyork.
select COUNT(*) as LoactionCount from Employee E 42. inner join Department Dept on E.DeptNumber=Dept.DepartmentNumber and Dept.Location = 'Newyork'

42.Which employees work in Newyork.

select * from Employee E inner join Department Dept on E.DeptNumber=Dept.DepartmentNumber and Dept.Location = 'Newyork'

43.Write a query to display as following Ename Date-Hired Smith June Fourteenth 1983 44.Print a list of employees displaying just salary if more than 1500. If exactly 1500 Display ON TARGET. If less than 1500 Display BELOW TARGET.
select e.EmployeeName,e.Sal , CASE WHEN e.Sal = 1500 THEN 'ON TARGET'

WHEN e.Sal < 1500 THEN 'BELOW TARGET' END from Employee e

45.List the employee names and the cited in which they work order by City. 46.Find the number of different employees and the number of Depts.
47.select count(distinct E.DeptNumber),COUNT(distinct E.employeeName) from Employee E

47.Determine the average salaries of employees


select AVG(Employee.Sal) from Employee Group by Employee.EmployeeNumber

48.List the Department number,Department name,Location and Local commission paid and total salary of each department.

select Department.DepartmentName,Department.Location,Department.DepartmentNumber,SUM( e.ComM) as LocalCommisionPaid,SUM(e.Sal)as TotalSal from Department inner join Employee e on e.DeptNumber=Department.DepartmentNumber 49. group by Department.DepartmentNumber,Department.Location,Department.DepartmentN ame

49.Display the average monthly salary bill for eachjob Type within a Department.

select AVG(Employee.Sal)as AvgSal,DeptNumber,Job from Employee group by DeptNumber,Job order by DeptNumber

50.To Display only those Jobs where the minimum salary is greater than or equal to 3000. 51.Find out the difference between highest and lowest salaries.
select (MAX(Employee.Sal)-MIN(Employee.Sal))as Diffrence Employee from

select Job from Employee group by Job having MIN(Employee.Sal)>=3000

52.Find all Depts. Which have more than 3 employees.


select Department.DepartmentName from Department inner join Employee E on Department.DepartmentNumber = E.DeptNumber group by Department.DepartmentName having COUNT(E.DeptNumber)>3

53.Check whether all employee numbers are indeed unique. 54.List lowest paid employees working for each manager. 55.Display all employee names and their department names in department name order.

56.Display all employee name,Department number and name. 57.Display the Department that has no employee.
select Department.DepartmentName from Department where Department.DepartmentNumber not in (Select DeptNumber from Employee)

58.Find all employees who joined the company before their manager 59.Find all employees who have same Job as Black.
60.select * from Employee where Job = (select Job from Employee where EmployeeName='blake')

60.Find the employees who earn more than the lowest salary in each department. 61.Display employees who earn more than the lowest salary in Dept No.30. 62.Find Employees who earn more than every employee in Dept No. 30.
63.select * from Employee where Sal > (select MAX(Sal) from Employee where DeptNumber= 30)

63.Find the job with the highest average salary.


64.select top 1 Job,AVG(sal) as NewSale from Employee group by Job order by NewSale Desc

64.Display the Name,Job,Hiredate for employees whose salary is greater than the highest salary in any sales dept.
select EmployeeName,Job,HireDate from Employee where Employee.Sal > (select MAX(Sal) as Job from Employee E inner join Department D on E.DeptNumber = D.DepartmentNumber 65. where D.DepartmentName='sales' )

65.Copy all inforamtion on department 10 into the D10 History table. 66.Delete all information about Department 10 from Employee table. 67.Create on Cluster table/Cluster Index on Emp(Dept No) and Dept(Dept No). 68.Create synonym on Emp Table. 69.Create Indes on Emp No. on Emp Table 70.List all tables which are created on a particular date 71.List all Indexes which are created on a particular date and table. 72.List all views which are created on particular date and table.

73.List all synonyms which are created for a particular table and date. 74.List all the objects which are created on a particular date. 75.To Display an Asterick against the row the most recently hired employees.Display Ename,Hiredate,and Column showing * and Column name maxdate(for unique records) 76.Delete the rows from Dept Table whose Dept No numbers does not matching rows in the Emp database.
77.select * from department where DepartmentNumber not in (select Employee.DeptNumber from Employee)

77.Select Ename,Job,Sal,MGR,Dept No for a given jobn title. 78.List the employee name and Salary increased by 15% and expressed as a whole number of dollars. 79.Display each employees name with hiredate,and review date.Assume review date is one year after hiredate.Order the output in ascending review date order.
80.select EmployeeName,HireDate,DATEADD(YEAR,1,HireDate) as ReviewDate from Employee order by ReviewDate asc

80.Write a Query which will return the day of the week,for any date entered in the format DD.MM.YY. 81.Employees hired on or before the 15th of any Month are paid on the last Friday of that Month.Those hired after the 15th are paid the last Friday of the following Month.Print a list of employees,their hiredate and first Pay date.Sort on hire dates. 82.List the Minimum and Maximum salary for each Job type. 83.Find the average salary and average total renumeration for each job type.Remember salesman earn commission. 84.Find all departments which have max than 3 employees.
85.select DeptNumber,D.DepartmentName 86. from 87. ( select COUNT(DeptNumber) as DeptCount,DeptNumber from Employee 88. group by DeptNumber 89. ) t 90. inner join Department D on t.DeptNumber = D.DepartmentNumber 91. group by t.DeptNumber,D.DepartmentName 92. having Max(t.DeptCount) > 3

85.List the employee name,Job,Salary,grade and department name for everyone in the company

except clerks,Sort on Salarydisplaying the highest salary first. 86.List the Ename,Job,Annual-Sal,Dept no.,Dname,Grade of employees who earn $36000 a year or who are clerks. 87.Show Ename,Salary,Dept no for any employee who earns a salary greater than the average for their department sort in department number order. 88.Who are the top 3 earners in the company? Display their name and salary.
89.select top 3 Employee.EmployeeName,Sal from Employee order by Sal desc 90.

91. 89.In which year did most people join the company? Display the year and number of employees. 90.Find employees who earn a salary greater than the average salary for their department. 91.Find all employees whose department is not in the Dept table. 92.It has been discovered that the sales people in dept 30 are not all males produce the following output. NAME DEPT NO JOB ALLEN 30 Sales Person WARD 30 Sales Person BLAKE 30 Manager 93.Find the employee who earns the minimum salary. 94.Display the name,Job,Hiredate,Sal for employees whose salary is greater than the highest salary in Sales Dept. 95.List Employees with either the same Job as Jones or a salary greater than or equal to Fords.In order by Job and salary. 96.List employees in Department 10 with the same job as anyone in the sales department. 97.List the employees having the same job as employees located in Chicago. 98.List employees whose salary is equal to that of SCOTT or WARD. 99.Set salaries of all salesman equal to 1.1 times the average salary of salesman 100. Delete all employees with the same job as JONES and Jones should not be deleted

S-ar putea să vă placă și