SQL
SQL
Q.1. Write SQL commands for the statements (a) to (h) and give outputs for SQL queries i(1) to i(4)
TABLE : EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7839 REA MANAGER 67 12-DEC-98 5000 0 10
1234 PREM CLERK 87 11-FEB-77 12000 1500 20
6754 SITA MANAGER 89 12-MAR-99 10000 1000 20
6574 GITA SALESMAN 98 11-JUN-99 9000 0 30
9876 HONEY CLERK 65 12-JUN-00 12000 800 20
8976 REEMA SALESMAN 91 10-SEP-88 6000 100 30
a) Display names of employees whose names include either of the substring “TH” or “LL”.
b) Display data of all employees sorted by their department, seniority and salary.
c) Find all the employees who have no manager.
d) To display all employees who were hired during 1995.
e) Show the average salary for all departments with more than 3 people for a job.
f) Find out number of employees having ‘MANAGER’ as job.
g) Create view DEPT20 with name and the salary of employees for dept 20.
h) Display department no. and number of employees in each department.
i) Find the output of the following :
1. SELECT SYSDATE FROM DUAL;
2. SELECT ENAME,SAL FROM EMPLOYEE WHERE DEPTNO=20;
3. SELECT COUNT(*) FROM EMP;
4. SELECT AVG(SAL) FROM EMP;
Q 2. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
WORKERS
W_ID FIRSTNAME LASTNAME ADDRESS CITY
102 Sam Tones 33 Elm St. Paris
105 Sarah Ackerman 440 U.S. 110 New York
144 Manila Sengupta 24 Friends Street New Delhi
210 George Smith 83 First Street Howard
255 Mary Jones 842 Vine Ave. Losantiville
300 Robert Samuel 9 Fifth Cross Wasington
335 Henry Williams 12Moore Street Boston
403 Ronny Lee 121 Harrison St. New York
451 Pat Thompson 11 Red Road Paris
DESIG
W_ID SALARY BENEFITS DESIGNATION
102 75000 15000 Manager
105 85000 25000 Director
144 70000 15000 Manager
210 75000 12500 Manager
255 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
451 28000 7500 Salesman
(i) To display W_ID, FIRSTNAME, ADDRESS and CITY of all employees living in NEW
YORK from the table WORKERS.
(ii) To display the content of workers table in ascending order of LASTNAME.
(iii) To display the FIRSTNAME, LASTNAME and total salary of all alerks from the tables
WORKERS and DESIGN, where total salary is calculated as SALARY + BENEFITS.
(iv) To display the minimum salary among Managers and Clerks from the table DESIG.
Q 3. (a)Write SQL commands for (a) to ( j) and write output for (h) on the basis of Teacher
relation given below.
Q. 5. Write the SQL commands for (a) to (d) and write the output for (e) on
the basis of table Hospital :