IP QUERIES For Practical File - 103902
IP QUERIES For Practical File - 103902
Table: EMP
1. Write a query to display Name, Sal, Empno and Job from table Emp.
SELECT ename, sal, empno, job
FROM Emp;
3. Write a query to display all the employees who are getting salary more than 20000.
SELECT *
FROM Emp
WHERE sal > 20000;
4. Write a query to display all the employees who are not Managers.
SELECT *
FROM Emp
WHERE job != ‘MANAGER’;
5. Write a query to display Name, Job and Salary of all the Clerks who are getting salary
less than 20000.
SELECT ename, job, sal
FROM Emp
WHERE sal < 20000 AND job = ‘CLERK’;
1
6. Write a query to display all the employees who are either from Deptno 10 or 20.
SELECT *
FROM Emp
WHERE deptno = 10 OR deptno = 20;
7. Write a query to list Name and Salary of all the employees who are getting salary
between 20000 and 35000.
SELECT ename, sal
FROM Emp
WHERE sal BETWEEN 20000 AND 35000;
8. Write a query to display all the employees who are either Managers, Clerks, Salesman
or Analysts.
SELECT *
FROM Emp
WHERE job IN (‘SALESMAN’ , ‘CLERK’ , ‘MANAGER’ ,
‘ANALYST’);
9. Write a query to display all the employees getting salary other than 10000, 20000,
30000, 40000 and 50000.
SELECT *
FROM Emp
WHERE sal NOT IN (10000 , 20000 , 30000 , 40000 , 50000);
10. Write a query to display all the employees whose names starts with alphabet M.
SELECT ename
FROM Emp
WHERE ename LIKE “M%”;
11. Write a query to display all the employees not having alphabet ‘a’ as second character
in their name.
SELECT ename
FROM Emp
WHERE ename NOT LIKE “_a%” ;
12. Write a query to display all the employees whose having NULL value in DeptNo
column.
SELECT *
FROM Emp
WHERE DeptNo IS NULL;
13. Write a query to display all the records in the alphabetical order of name.
SELECT *
FROM Emp
ORDER BY ename ASC;
2
14. Write a query to display employee Name, Job and Salary of Managers and Clerks in
the order of their salary from highest to lowest.
SELECT ename, job, salary
FROM Emp
WHERE job = ‘MANAGER’ OR job = ‘CLERK’
ORDER BY salary DESC;
15. Write a query to display Name and New Salary of employees. New Salary is Salary +
10% of Salary.
SELECT ename, sal + sal*10/100 AS “New Salary”
FROM Emp;
16. Write a query to display names of all the employees in uppercase alphabet and
number of characters in their name.
17. Write a query to display names of all the employees and first four characters of their
Job.
18. Write a query to display name, job and hiredate of all the employees who have joined
in year 2012.
3
Grouping Result: (GROUP BY clause)
23. Write a query to display Total Salary paid to the employees of each department.
SELECT deptno, SUM(sal)
FROM Emp
GROUP BY deptno;
25. Write a query to display all the jobs where the number of employees are less than 3.
SELECT job, COUNT(*)
FROM Emp
GROUP BY job
HAVING COUNT(*) < 3;
----- X -----