DBMS Lab-I - Questions
DBMS Lab-I - Questions
SET-1
5. Show the record of employees earning salaries greater than 1600 in each department.
6. Display the lowest paid and highest paid employee details under each department.
8. Display the department names which are having more than 5 employees.
10. Display the department names whose salary budget crossed 1lakh.
mysql> select dname from dept where deptno IN (select deptno from emp group by deptno having
sum(sal)>9000);
+-------+
| dname |
+-------+
| SALES |
+-------+
1 row in set (0.17 sec)
SET-2
1. Find all information about the sailors who have reserved boat number 101.
3. Find the names of sailors who have reserved a red boat, and list them in the order of age.
4. Find the names of sailors who have reserved at least one boat.
6. Find the ids of sailors who have reserved a red or green boat.
mysql> SELECT R.sid
-> FROM Boats B, Reserves R
-> WHERE R.bid = B.bid AND B.color = 'red'
-> UNION
-> SELECT R2.sid
-> FROM Boats B2, Reserves R2
-> WHERE R2.bid = B2.bid AND B2.color = 'green';
+-----+
| sid |
+-----+
| 22 |
| 31 |
| 64 |
| 74 |
+-----+
4 rows in set (0.16 sec)
10. Find the average sailor’s age for each rating level with at least two sailors.
+--------+--------+
| rating | avgage |
+--------+--------+
| 7| 40 |
| 8 | 40.5 |
| 10 | 25.5 |
| 3 | 44.5 |
+--------+--------+
1. List the E_no, E_name, and Salary of all employees working for MANAGER.
2. Display all the details of the employee whose salary is more than the Sal of any CLERK
mysql> select * from emp where sal> any( select sal from emp where job='CLERK');
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
12 rows in set (0.01 sec)
.
3. List the employees in the ascending order of Designations of those joined after 1981.
mysql> SELECT *
-> FROM emp
-> WHERE hiredate>('1981-01-01') order by job;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
+-------+--------+-----------+------+------------+---------+---------+--------+
12 rows in set (0.01 sec)
4. List the employees along with their Experience and Daily Salary.
7. List the employees who are working for the Deptno 10 or20.
mysql> SELECT *
-> FROM emp
-> where ename like 's%';
+-------+-------+-------+------+------------+--------+------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+-------+-------+------+------------+--------+------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
+-------+-------+-------+------+------------+--------+------+--------+
1 row in set (0.02 sec)
9. Display the name as well as the first five characters of name(s) starting with ‘H’
10. List all the emps except ‘PRESIDENT’ & ‘MANAGER” in asc order of Salaries.
SET-4
1. Allow NULL for all columns except ename and job. (Either in Create command or Alter Command)
2. Add constraints to check, while entering the empno value (i.e) empno > 1000.
5. Create a default constraint and provide a salary value of "1000" if the salary is not provided.
6. Add the hire_date, bdate columns to the existing table and insert the values in the column.
7. Display the most experienced employee details.
8. Display the employee details who was born on august 15th.
9. Display the employee details as follows
CLARK working as MANAGER in the ACCOUNTING department
SMITH working as CLERK in the RESEARCH department
10. Display all the employees and the departments implementing a left outer join.
5. Display the Employee Id and Employee Name who works in the department of Marketing.
9. Create another dummy table Emp_Dum and copy only specific columns (Emp_no, E_name,Job_id) of
EMPLOYEE table.
10. List all Employee names, salary and 15% rise in salary. Label the column as a pay hike.