TSQL
TSQL
1. List the names and hire dates in format ('20/3/84') in dept 20.
2. How many months has the president worked for the company
3. List the names of all employees where hire date is in month of December
4. Give SQL command to find average annual salary per job in each department
6. Compute average, minimum and maximum salaries of employees for each department:
-> SELECT ename, job, hiredate FROM employee e WHERE hiredate IN(SELECT
min(hiredate) FROM employee WHERE e.deptno =deptno );
9. Show count of employees and their total sum of salary. Display only those jobs
where minimum salary is greater than or equal to 3000
10. Find out difference between highest and lowest salaries from emp table
12. Find the employees who earn more than the lowest salary in each department.
->select ename, sal from employee where sal >ANY (select sal from employee e,
department d where e.deptno=d.deptno);
13. Display employee who earn more than the lowest salary in department 30
->select ename, sal from employee where sal >ANY (select sal from employee
where deptno=30);
14. Find employees who earn more than every employee in each department ordering to
the department.
->select job, sal from employee where sal > ALL (SELECT avg(sal) from
employee);
17. Display the name of job, hire date for employees whose salary is greater than
the highest salary in any SALES department
->select job, hiredate, ename, sal from employee where sal > ALL (select sal
from employee where deptno=30);
alternate method:
->select job, hiredate, ename, sal from employee where sal > ALL (select sal
from employee where deptno=(select deptno from department where dname="SALES"));
18. Find out all the jobs either in department 20 or where salary is greater than
3000.
19. Find out the employees who earn the highest salary in each department.
20. Display the employees who are doing the same job as �FORD�.
->select ename, job from employee where job=(select job from employee where
ename="FORD)