Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

SQL Part 1 Q&A

The document contains a comprehensive list of SQL practice questions focusing on various queries related to employee and department data. It includes commands for displaying employee details, calculating salaries, filtering by job titles and departments, and performing aggregate functions. Each question is presented with the corresponding SQL query for practice and learning purposes.

Uploaded by

Pradeep Maji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL Part 1 Q&A

The document contains a comprehensive list of SQL practice questions focusing on various queries related to employee and department data. It includes commands for displaying employee details, calculating salaries, filtering by job titles and departments, and performing aggregate functions. Each question is presented with the corresponding SQL query for practice and learning purposes.

Uploaded by

Pradeep Maji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL Practice Questions - I

1. Display the dept information from DEPT table.


SELECT *
FROM DEPT;

2. Display the details of all employees from the EMP table.


SELECT *
FROM EMP;

3. Display the name and job for all employees.


SELECT ENAME, JOB
FROM EMP;

4. Display name and salary for all employees.


SELECT ENAME, SAL
FROM EMP;

5. Display employee number and total salary for each employee.


SELECT EMPNO, SAL+COMM
FROM EMP;

6. Display employee name and annual salary for all employees.


SELECT ENAME, SAL*12 ANNUAL_SAL
FROM EMP;

7. Display the names of all employees who are working in department number 10.
SELECT ENAME
FROM EMP
WHERE DEPTNO = 10;

8. Display the names of all employees working as clerks and drawing a salary of
more than 3000.
SELECT ENAME
FROM EMP
WHERE JOB = ‘CLERK’ AND SAL > 3000;

Anjana Kuiri
9. Display employee number and names for employees who earn commission.
SELECT EMPNO, ENAME
FROM EMP
WHERE COMM IS NOT NULL AND COMM > 0;
10. Display names of employees who do not earn any commission.
SELECT EMPNO, ENAME
FROM EMP
WHERE COMM IS NULL AND COMM = 0;
11. Display the names of employees who are working as clerk, salesman or analyst and
drawing a salary more than 3000.
SELECT ENAME
FROM EMP
WHERE (JOB = ‘CLERK’ OR JOB = ‘SALESMAN’ OR JOB = ‘ANALYST’)
AND SAL > 3000;
or,
SELECT ENAME
FROM EMP
WHERE JOB IN (‘CLERK’, ‘SALESMAN’, ‘ANALYST’) AND SAL>3000;
12. Display the names of employees who are working in the company for the past
5 years.
SELECT ENAME
FROM EMP
WHERE SYSDATE-HIREDATE > 5*365;
13. Display the list of employees who have joined the company before 30 th June 90 or
after 31st dec 90.
SELECT *
FROM EMP
WHERE HIREDATE BETWEEN ‘30-JUN-1990’ AND ‘31-DEC-1990’;
14. Display current date.
SELECT SYSDATE
FROM DUAL;
15. Display the list of users in your database (using log table).
SELECT *
FROM DBA_USERS;

Anjana Kuiri
16. Display the names of all tables from the current user.
SELECT *
FROM TAB;

17. Display the name of the current user.


SHOW USER;

18. Display the names of employees working in department number 10 or 20 or 40


or employees working as clerks, salesman or analyst.
SELECT ENAME
FROM EMP
WHERE DEPTNO IN (10, 20, 40) OR JOB IN (‘CLERK’, ‘SALESMAN’,
‘ANALYST’);

19. Display the names of employees whose name starts with alphabet S.
SELECT ENAME
FROM EMP
WHERE ENAME LIKE ‘S%’;

20. Display employee names for employees whose name ends with alphabet S.
SELECT ENAME
FROM EMP
WHERE ENAME LIKE ‘%S’;

21. Display the names of employees whose names have second alphabet A in their names.
SELECT ENAME
FROM EMP
WHERE ENAME LIKE ‘_A%’;

22. Display the names of employees whose names are exactly five characters in length.
SELECT ENAME
FROM EMP
WHERE LENGTH(ENAME) = 5;
or,
SELECT ENAME
FROM EMP
WHERE ENAME LIKE ‘_____’;

Anjana Kuiri
23. Display the names of employees who are not working as SALESMAN or CLERK or
ANALYST.
SELECT ENAME
FROM EMP
WHERE JOB NOT IN (‘CLERK’, ‘SMAN’, ‘ANALYST’);

24. Display the total number of employees working in the company.


SELECT COUNT(*)
FROM EMP;

25. Display the total salary being paid to all employees.


SELECT SUM(SAL)+SUM(NVL(COMM,0))
FROM EMP;

26. Display the maximum salary from emp table.


SELECT MAX(SAL)
FROM EMP;

27. Display the minimum salary from emp table.


SELECT MIN(SAL)
FROM EMP;

28. Display the average salary from emp table.


SELECT AVG(SAL)
FROM EMP;

29. Display the maximum salary being paid to CLERK.


SELECT MAX(SAL)
FROM EMP
WHERE JOB = ‘CLERK’;

30. Display the maximum salary being paid in dept no 20.


SELECT MAX(SAL)
FROM EMP
WHERE DEPTNO = 20;

Anjana Kuiri
31. Display the total salary drawn by an analyst working in dept no 40.
SELECT SUM(SAL)+SUM(NVL(COMM,0))
FROM EMP
WHERE DEPTNO = 40 AND JOB = ‘ANALYST’;

32. Display the names of employees in order of salary i.e. the name of the employee
earning the lowest salary should appear first.
SELECT ENAME
FROM EMP
ORDER BY SAL;

33. Display the names of employees in descending order of salary.


SELECT ENAME
FROM EMP
ORDER BY SAL DESC;

34. Display empno, ename, deptno, and sal. Sort the output first based on name and
within name by deptno and within deptno by Sal;
SELECT EMPNO, ENAME, DEPTNO, SAL
FROM EMP
ORDER BY ENAME, DEPTNO, SAL;

35. Display dept numbers and total number of employees within each group.
SELECT DEPTNO, COUNT(*)
FROM EMP
GROUP BY DEPTNO;

36. Display department numbers and maximum salary for each department.
SELECT DEPTNO, MAX(SAL), MIN(SAL)
FROM EMP
GROUP BY DEPTNO;

37. Display the various jobs and total salary for each job.
SELECT JOB, SUM(SAL)
FROM EMP
GROUP BY JOB;

Anjana Kuiri
38. Display the department numbers with more than three employees in each dept.
SELECT DEPTNO, COUNT(*)
FROM EMP
GROUP BY DEPTNO
HAVING COUNT(*) > 3;

39. Display the various jobs along with total salary for each of the jobs where total
salary is greater than 40000.
SELECT JOB, SUM(SAL)
FROM EMP
GROUP BY JOB
HAVING SUM(SAL) > 40000;

40. Display the name of emp who earns highest salary.


SELECT ENAME
FROM EMP
WHERE SAL = (SELECT MAX(SAL)
FROM EMP);

41. Display the employee number and name of employee working as CLERK and
earning the highest salary among CLERKS.
SELECT EMPNO, ENAME
FROM EMP
WHERE JOB = ‘CLERK’
AND SAL = (SELECT MAX(SAL)
FROM EMP
WHERE JOB = ‘CLERK’);

42. Display the names of the salesman who earns a salary more than the highest salary of
any clerk.
SELECT ENAME
FROM EMP
WHERE JOB = ‘SALESMAN’
AND SAL > (SELECT MAX(SAL)
FROM EMP
WHERE JOB = ‘CLERK’);

Anjana Kuiri
43. Display the names of clerks who earn salary more than that of James or that of salary
lesser than that of Scott.
SELECT ENAME
FROM EMP
WHERE JOB = ‘CLERK’
AND SAL < (SELECT SAL FROM EMP WHERE ENAME = ‘SCOTT’)
AND SAL > (SELECT SAL FROM EMP WHERE ENAME = ‘JAMES’);

44. Display the names of employees who earn a salary more than that of James or that of
salary greater than that of Scott.
SELECT ENAME
FROM EMP
WHERE SAL > (SELECT SAL FROM EMP WHERE ENAME = ‘JAMES’)
OR SAL > (SELECT SAL FROM EMP WHERE ENAME = ‘SCOTT’);

45. Display the name of the employees along with their annual salary. The name of the
employees earning the highest annual salary should appear first.
SELECT ENAME, (SAL+NVL(COMM,0))*12 ANNUAL_SAL
FROM EMP
ORDER BY (SAL+NVL(COMM,0))*12 DESC;

Anjana Kuiri

You might also like