0% found this document useful (0 votes)
83 views

Create Tables With Following Structure

The document contains instructions to create tables in a MySQL database to store employee and department data, and populate them with sample records. It then lists 20 queries to practice skills by retrieving data from the tables, such as finding managers and clerks in department 20, employees earning between $1200-1400, and details of managers and clerks in department 10.

Uploaded by

PRABHAT SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Create Tables With Following Structure

The document contains instructions to create tables in a MySQL database to store employee and department data, and populate them with sample records. It then lists 20 queries to practice skills by retrieving data from the tables, such as finding managers and clerks in department 20, employees earning between $1200-1400, and details of managers and clerks in department 10.

Uploaded by

PRABHAT SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PRABHAT SINGH

ASSIGNMENT NO 1.
[email protected]
DATE – 24/08/2022

Create tables with following structure. These tables are readily available in Oracle database, however,
you can easily create these in MySQL or other RDBMS using scripts mentioned in various online
tutorials such as http://oraclemine.com/emp-and-dept-tables-in-oracle/

Salgra
Emp Dept
de
DEPTNO GRAD
EMPNO          ENAME          JOB            MGR            HIREDATESAL        
DNAME    ELOS
COMM           DEPTNO         
LOC    AL
HISAL
 
Post table creation and populating with sample data, try writing queries from below list to practice your skills

 
Mandatory

1. Find the details of all the managers (in any dept) and clerks in dept 20.
2.
3. Find the details of all the managers in dept. 10 and all clerks in dept 20 and all employees who are neither
managers nor clerks but whose salary is more than or equal to 2000/-.
4. Find the names of anyone in dept. 20 who is neither manager nor clerk.
5. Find the names of employees who earn between 1200/- and 1400/-.
6. Find the employees who are clerks, analysts or salesmen.
7. Find the employees who are not clerks, analysts or salesmen.
8. Find the employees who do not receive commission.
9. Find the different jobs of employees receiving commission.

 
Recommended

10. Query Emp table.


11. Select the employees in department 30.
12. List the names, numbers and departments of all clerks.
13. Find the department numbers and names of employees of all departments with deptno greater than 20.
14. Find employees whose commission is greater than their salaries.
15. Find employees whose commission is greater than 60 % of their salaries.
16. List name, job and salary of all employees in department 20 who earn more than 2000/-.
17. Find all salesmen in department 30 whose salary is greater than 1500/-.
18. Find all employees whose designation is either manager or president.
19. Find all managers who are not in department 30.
20. Find all the details of managers and clerks in dept 10.

create database company1;


use company1;
create table emp(EmpNo int,EmpName varchar(20),job varchar(20),mgr
int,Hiredate date,sal int,Comm int,DeptNo int);
insert into emp(EmpNo,EmpName,job,mgr,Hiredate,sal,Comm,DeptNo)
values
(7369,'smith','clerk',7902,'1980-12-17',800,0,20),
(7499,'allen','salesman',7698,'1980-02-20',1600,300,30),
(7521,'ward','salesman',7698,'1981-02-22',1250,500,30),
(7566,'jones','manager',7839,'1981-04-22',2975,0,30),
(7654,'martin','salesman',7698,'1981-09-28',800,0,20),
(7698,'blake','manager',7839,'1981-05-01',2850,0,30),
(7782,'clark','manager',7839,'1981-01-09',2450,0,10),
(7839,'king','president',0,'1981-11-17',500,0,10);
select * from emp;
/*Creating */
/*creating Dept table*/
create table dept(deptno int,dname varchar(20),loc varchar(20));
insert into dept(deptno,dname,loc) values
(10,'accounting', 'new york'),(20,'research','dallas'),(30,'sales','chicago'),
(40,'operations','boston');
select * from dept;

/*Create salgrade Table*/


create table salgrade(grade int,losal int,hisal int);
insert into salgrade(grade,losal,hisal) values
(1,700,1200),(2,1201,1400),(3,1401,2000),(4,2001,3000),(5,3000,9999);
Select * from salgrade;
ANSWER -

'1'

select * from EMP where Job = 'MANAGER' or Job = 'CLERK' and DEPTNO =
20 ;

'2'

'3'

Select ENAME from EMP where DEPTNO = 20 and Job != 'MANAGER' && Job
!= 'CLERK';

'4'

select ENAME from EMP where SAL between 1200 and 1400;

'5'

select * from EMP where JOB = 'CLERK' or JOB = 'ANALYST' or JOB =


'SALESMAN';

'6''1'

Select * from EMP where Job = 'MANAGER'or Job = 'CLERK' and DEPTNO =
20 ;

'2'

'3'

select ENAME from EMP where DEPTNO = 20 and Job!= 'MANAGER' &&
Job != 'CLERK';

'4'

select ENAME from EMP where SAL between 1200 and 1400;

'5'

select * from EMP where JOB = 'CLERK' or JOB = 'ANALYST' or JOB =


'SALESMAN';

'6'
select * from EMP where JOB != 'CLERK' and JOB != 'ANALYST' and JOB !=
'SALESMAN';

'7'

select * from EMP where COMM is null;

'8'

select JOB from EMP where COMM is not null;

'9'

select * from EMP

'10'

select * from EMP where DEPTNO = 30;

'11'

select EMPNO, ENAME, DEPTNO from EMP where JOB ='CLERK';

'12'

select DEPTNO,ENAME from EMP where DEPTNO > 20;

'13'

select * from EMP where (COMM*SAL) > (SAL*0.6);

'14'

select ENAME, JOB, SAL from EMP where DEPTNO = 20 and SAL > 2000;

'15'

select * from EMP where DEPTNO = 30 and Job ='SALESMAN' and SAL >
1500;

'16'

select * from EMP where Job = 'MANAGER' or Job = 'PRESIDENT'

'17'

select * from EMP where DEPTNO != 30 and JOB ='MANAGER';


'18'

select * from EMP where DEPTNO=10 or JOB = 'CLERK' or JOB =


'MANAGER';

select * from EMP where JOB != 'CLERK' and JOB != 'ANALYST' and JOB !=
'SALESMAN';

‘19’

Find all managers who are not in department .*/


select * from emp where job='manager' and DeptNo !=30;

‘20’

Find all the details of managers and clerks in dept 10.*/


select * from emp where job='manager' and 'clerk' or DeptNo=10;

You might also like