You are on page 1of 9

PART II

Write SQL statements for questions 1 to 5 using the table EMP


Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Display details of all employees who earn between 10000 and 25000
_____________________________________________________________________
_____________________________________________________________________
2. Find the number of employees in the each department
_____________________________________________________________________
_____________________________________________________________________
3. Create a view containing details of employees of department number 20
_____________________________________________________________________
_____________________________________________________________________
4. Display details of all employees according to their department and seniority
_____________________________________________________________________
_____________________________________________________________________
5. Find all employees who are not managers
_____________________________________________________________________
_____________________________________________________________________

PART II
Write SQL statements for questions 1 to 5 using the table EMP
Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Find the lowest paid employee


_____________________________________________________________________
_____________________________________________________________________
2. List average salary of programmers
_____________________________________________________________________
_____________________________________________________________________
3. List the employees who earn a salary greater than the average salary earned by the
employees of dept 10
_____________________________________________________________________
_____________________________________________________________________
4. Display name, annual salary and commission of all salesmen whose monthly salary is
greater than commission
_____________________________________________________________________
_____________________________________________________________________
5. Find the number of departments
_____________________________________________________________________
_____________________________________________________________________

PART II
Write SQL statements for questions 1 to 5 using the table EMP
Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Add an attribute Annual_sal to store the annual salary


_____________________________________________________________________
_____________________________________________________________________
2. List all employees who joined before 1995
_____________________________________________________________________
_____________________________________________________________________
3. Increase the salary of Divakar by 5000
_____________________________________________________________________
_____________________________________________________________________
4. List the maximum and minimum salary of each job type
_____________________________________________________________________
_____________________________________________________________________
5. List the employee whose commission is greater than their salary
_____________________________________________________________________
_____________________________________________________________________

PART II
Write SQL statements for questions 1 to 5 using the table EMP
Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Find the number of salesmen


_____________________________________________________________________
_____________________________________________________________________
2. List average salary of all departments which have more than 3 employees
_____________________________________________________________________
_____________________________________________________________________
3. Create a view dept10 containing empno, ename and annual salary of employees in the
dept 10
_____________________________________________________________________
_____________________________________________________________________
4. Find the jobs that were filled in the first half of 1995
_____________________________________________________________________
_____________________________________________________________________
5. Insert a row with the following details:
1059, Rajesh, 01-10-2000, salesman, 30, 12000, 2000
_____________________________________________________________________
_____________________________________________________________________

PART II
Write SQL statements for questions 1 to 5 using the table EMP
Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Give an incentive of Rs.5000 for the employees who joined before 1990
_____________________________________________________________________
_____________________________________________________________________
2. List the employees of software department drawing salary less than 40,000
_____________________________________________________________________
_____________________________________________________________________
3. List the employee who earns the highest in his/her department
_____________________________________________________________________
_____________________________________________________________________
4. Find the departments that have more than 2 types of job
_____________________________________________________________________
_____________________________________________________________________
5. Delete the employee with code 1010
_____________________________________________________________________
_____________________________________________________________________

PART II
Write SQL statements for questions 1 to 5 using the table EMP
Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Give the command to create the table EMP with the following constraints
Empno NOT NULL, primary key
Ename NOT NULL
Salary Default 12000 and salary >12000 and < 50000
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
2. List the lowest paid manager
_____________________________________________________________________
_____________________________________________________________________
3. Find the average salary and average total remuneration for each type. Remember
salesmen earn commission
_____________________________________________________________________
_____________________________________________________________________
4. Find all departments which have more than 2 employees
_____________________________________________________________________
_____________________________________________________________________

PART II
Write SQL statements for questions 1 to 5 using the table EMP
Empno

EName

DOJ

Job

Dept_no

Salary

1010

Karan

01/06/80

Director

40

48,000

1023

Divakar

01/03/84

Manager

10

20,000

1038

Divya

01/05/94

Programmer

20

40,000

1055

Atul

01/09/95

Analyst

20

45,000

1059

Hritik

01/06/97

Programmer

20

40,000

1062

Akshay

01/08/99

Manager

30

25,000

1064

Ajay

01/10/99

Clerk

10

12,000

1066

Sanjay

01/02/00

Salesman

30

15,000

Comm

5000

1. Remove the row which has any of empno: 1010, 1038, 1062
_____________________________________________________________________
_____________________________________________________________________
2. Assume that there is one more table DEPT in the database as shown below:
Dept_no
Dname
Location
10
Accounts
Jayanagar
20
Software
Indiranagar
30
Sales
Rajajinagar
40
Research
Koramangala
Give the query to display number, name, dept, location of employees earning more than
25000
_____________________________________________________________________
_____________________________________________________________________
3. Give the query to join the two tables EMP and DEPT
_____________________________________________________________________
_____________________________________________________________________
4. List the total number of employees
_____________________________________________________________________
_____________________________________________________________________

PART I
1) Write SQL commands for (a) to (d) using the following table FRIENDS :
No

Name

Address

DOB

Age

Karan

14, Golden Enclave

01-01-1980

18

Divakar

45, Vasant Vihar

10-02-1981

17

Divya

30, Sony Villa

15-03-1981

17

Atul

35, Silver Terrace

28-05-1980

18

Sanjay

5, Wilson Garden

18-06-1982

16

a)

Add a new column, phone number to the table FRIENDS


_____________________________________________________________________

_____________________________________________________________________
b) List the names in the ascending order of age
_____________________________________________________________________
_____________________________________________________________________
c) Increase age by 1 for all those born betweeen January and March
_____________________________________________________________________
d)

_____________________________________________________________________
Display all names which have r or y in them
_____________________________________________________________________
_____________________________________________________________________

2)

Give the output of the following commands:

a)

Select MIN(age) from friends;


_____________________________________________________________________

b)

Select COUNT(*) from friends where age <= 17;


_____________________________________________________________________

PART I
1) Write SQL commands for (a) to (d) using the following table FRIENDS :
No

Name

Address

DOB

Age

Karan

14, Golden Enclave

01-01-1980

18

Divakar

45, Vasant Vihar

10-02-1981

17

Divya

30, Sony Villa

15-03-1981

17

Atul

35, Silver Terrace

28-05-1980

18

Sanjay

5, Wilson Garden

18-06-1982

16

a)

Create a view containing name, address


_____________________________________________________________________

_____________________________________________________________________
b) Change address to 1, Ram Sadan for name = Sanjay
_____________________________________________________________________
_____________________________________________________________________
c) Add a new row to the table. Use the following data :
Ravi, 45, Rose Garden, 20-08-81, 17
_____________________________________________________________________
d)

_____________________________________________________________________
List all those friends who are born in the year 1981
_____________________________________________________________________
_____________________________________________________________________

2)
a)

Give the output of the following commands:


Select MAX(age) from friends;
_____________________________________________________________________

b)

Select COUNT(DISTINCT age) from friends;


_____________________________________________________________________

You might also like