Académique Documents
Professionnel Documents
Culture Documents
(3): Calculate the employee salary with increase of 300$ for all employee?
Ans: select Sal+300 AS 'Increased Salary' from emp;
(15):Display name,sal of employees who earn more then 1500 and not in dept
10,30 ?
Ans: select ename, Sal from employee where Sal>1500 and did Not In(10,30);
(16):Display the average, highest, lowest & sum of monthly salaries for all
employees?
Ans: select avg(Sal) as 'Average Monthly Salary', max(Sal) as 'Highest Monthly
Salary', min(Sal) as 'Lowest Monthly Salary', sum(Sal) as 'Sum Monthly Salary'
from emp Group by Ename, empno, sal;
(17):Display e_name that is first and empname that are last in alphabetized list
of all employees?
Ans: select ename from emp order by ename desc;
(19):Display dept_id and average salaries of those dept that have an average
sallary greater than 2000$?
Ans: select did,avg(Sal) from department Group by did,ename,sal Having
avg(sal)>2000;
Join Queries
1)Display the employee name and department number for all employees?
Ans: SELECT employee.e_name, employee.did, department.d_name FROM
employee,department WHERE employee.did = department.did;
2)Create a unique listing of all jobs that are in department 30, include the
location of department 30.
Ans: SELECT DISTINCT employee.job, department.loc FROM employee ,
department WHERE employee.did = department.did AND employee.did =
30;
3)Display ename,dname and loc of all employees who earns a commision.
Ans: SELECT employee.e_name, department.d_name, department.loc FROM
employee , department WHERE employee.did = department.did AND
employee.comm IS NOT NULL;
5)Display the enames and empno along with their manager's names and
manager numbers.Label the colums Employee, E#, Manager and Mgr#.
Ans: select e.e_name as 'Employee',e.emp_id as 'E#',manager.mgr_id as
'Mgr#',manager.mgr_name as 'Manager' from employee e, employee
manager where e.mgr=manager.emp_id;
6)Display the ename and hiring date of any employee who are hired after
employee 'Blake'.
Ans: select e.e_name,e.hiring_date from employee, employee blake where
blake.ename ='Blake' and blake.hirng_date < employee.hirng_date;
SubQueries
1) Display ename and hiring date of all employees who are in the same
department as employee 'Blake'?
Ans: select e_name,hiring_date from employee where did IN (select did from
employee where e_name='Blake') and e_name!='Blake';
2) Display ename and empno of all employees who earns more than the
average salary. sort in descending order.
Ans: select emp_id,e_name from employee where Sal>(select avg(Sal) from
employee) order by Sal Desc;
3)Display ename and empno of all employees who works in a dept with any
employee whose name contains a 'T'?
Ans: select emp_id,e_name from employee where did in (select did from
employee where e_name like '%T%');
4)Write a query to display the name and deptno and salary of all employees
whose deptno and salary matches the deptno and salary of any employee who
earns a comm?
Ans: select e_name, did, Sal from employee where (did,Sal) in (select did,Sal
from employee where comm is not null);
5)Display ename and empno of all employees that earns a salary that is higher
than the salary of all of the clerks. Sort result on salary from highest to lowest.
Ans: select e_name,job,Sal from employee where Sal > All (select Sal from
employee where job='Clerk') order by Sal Desc;