Sei sulla pagina 1di 4

MSc SQL LAB 2

1. Display all the data from emp for those employees who are MANAGERs or who
are CLERKs that work in department 20.

SELECT * FROM EMP WHERE DEPTNO=20 AND JOB IN ("CLERK","MANAGER")

2. Display all details from emp for any employee whose name contains the letter S
or A.
SELECT * FROM EMP WHERE ENAME LIKE "%A%" OR ENAME LIKE %S%"

3. Display the total take home (Salary +Comm) pay for all employees;
select ename, sal+ifnull(comm,0) from emp
4. Display the salary and salary with a 10% increase (with a heading of “10%
Increase” for all employees).
????????????????????????
5. Display the employee name and job separated by a comma and with a heading of
NAMEJOB.
??????????????????/
6. Display the average salary for each department.

select deptno,avg(sal) from EMP group by deptno

7. Display the max salary, min salary and average salary for all employees grouped
by job.
Select job, max(sal) as mac, min(sal) as min, avg(sal)as avg from emp group
by job

8. Display the number of employees in each job in each department in the


company. Also list the department they are in, the job title, the sum of the
salaries of each employee type in each department, the average salary of each
employee type in each department, and show the information grouped by
department name and job.

Hint : Use sum(sal), count(*), avg(sal) and group by.
Note : Count(*) counts the number of rows in each group as
defined by the 'group by' command.
Note : Sum and Avg work the groups of rows as defined by the
'group by' command.
??????????????????????
9. Show the same information as query 8 does but only show the groups having at
least two employees.
???????????????????????
10. Display the job, max take home pay (Salary+Comm), and number of employees
that fall into the category for all employees grouped by job;
????????????????
11. Add a record containing a new department number (50), name
(PENSIONS) and location (CHICAGO) into the DEPT table.
insert INTO DEPT VALUES (50,"PENSIONS","CHICAGO")

12. Display the employee name and department location of the


employee called ADAMS.
Select ENAME, DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO=DEPT.DEPTNO AND ENAME="ADAMS"

13. Display the maximum salary paid in each department.


SELECT DEPTNO, MAX(SAL) FROM EMP GROUP BY DEPTNO

14. Update the Dept table to change the location of Department Number 50 to Miami.
UPDATE DEPT set LOC="Miami" WHERE DEPTNO=50

15. Display the employee name and total salary of all employees who
are salesmen.
SELECT ENAME, SAL+IFNULL(COMM,0) FROM emp WHERE JOB="SALESMAN"

16. Delete all records in the Dept table which have a department
number of 50 and then view the contents of the table to ensure
that the operation has been completed correctly.

DELETE FROM DEPT WHERE DEPTNO=50

Potrebbero piacerti anche