Вы находитесь на странице: 1из 5

BBA VII Semester

Database Management System

Assignment# 2

Due Date: 17 th November, 2016 at start of class

Assignment should be handwritten and properly documented.

Total Marks:100

THE SAMPLE TABLES

EMP

EMPNO

ENAME

JOB

MGR

HIREDATE

SAL

COMM

DEPTNO

7369

SALMAN

CLERK

7902

17-DEC-2000

8000

 

20

7499

ALIA

SALESMAN

7698

20-FEB-2001

16000

3000

30

7521

WAHEED

SALESMAN

7698

22-FEB-2001

12500

5000

30

7566

JAMIL

MANAGER

7839

02-APR-2001

29750

20

7654

MEHVISH

SALESMAN

7698

28-SEP-2001

12000

12500

30

7698

BILAL

MANAGER

7839

01-MAY-2001

28500

30

7782

QASIM

MANAGER

7839

09-JUN-2001

24500

10

7788

SHAMS

ANALYST

7566

09-DEC-2002

30000

20

7839

KAMRAN

PRESIDENT

17-NOV-2001

50000

7844

TANVEER

SALESMAN

7698

08-SEP-2001

15000

0

30

7876

AFTAB

CLERK

7788

12-JAN-2003

11000

20

7900

JAVERIA

CLERK

7698

03-DEC-2001

9500

30

7902

FOZIA

ANALYST

7566

03-DEC-2001

30000

20

7934

MURAD

CLERK

7782

23-JAN-2002

13000

10

DEPT

DEPTNO

DNAME

LOC

10

ACCOUNTING

ISLAMABAD

20

RESEARCH

KARACHI

30

SALES

LAHORE

40

OPERATIONS

QUETTA

SALGRADE

GRADE

LOSAL

HISAL

1

7000

12000

2

12010

14000

3

14010

20000

4

20010

30000

5

30010

99990

Kamran Shaukat Dar Lecturer IT

BBA VII Semester

Database Management System

Assignment# 2

The SELECT statement

SELECT

Specification of desired

columns FROM

Specification of table or tables

WHERE

Selection criteria for rows

ORDER BY

Sorting sequence of rows of result table

Kamran Shaukat Dar Lecturer IT

BBA VII Semester

Database Management System

Assignment# 2

EXERCISES

A1

Display the contents of the DEPT, EMP and SALGRADE tables. [Check your results against the tables listed.]

 

Select * from Emp

To produce an answer to the request "Give a list of all employees showing their employee number, name & department number." We will require the following SQL statement,

Select EmpNo, Ename, DeptNo from Emp

 

A2

Display the name and commission of all the employees.

 

A3

Display the name and commission of all the employees together with another column that shows their commission increased by 10%.

A4

Display the job title of all the employees.

To remove duplicates within the result table, use:

 

SELECT DISTINCT column1, column2, etc

FROM

table-name;

A5

Display all the different job titles which currently exist in the company.

 

SELECT from a single table using the WHERE condition

WHERE

=, <>, >, >=, <, <=, (!= means not equal) comparison operators

NOT, AND, OR

logical operators

WHERE

column BETWEEN field value AND field value

WHERE

column IN (field value, field value,

,

)

WHERE

column LIKE '%charstring%' (% means skip 0 or any no of characters; use _ for exactly one character)

WHERE

column IS NULL

(All these operators can be negated by using NOT)

A6

Display the employee number, name and current job of all those who work in Department

30.

A7

Display the names of all the clerks, showing their employee number and that of their manager.

A8

Display details of all clerks, analysts and salesmen.

A9

Display details of employees who are not clerks, analysts or salesmen.

A10

Display details of all employees whose commission is greater than salary.

A11

Display employee name, job and department number for employees whose names begin with

Kamran Shaukat Dar Lecturer IT

BBA VII Semester

Database Management System

Assignment# 2

‘M’.

A12

Display details of employees whose salaries are not between 12,000 and 14,000.

A13

Display details of salesmen and managers in dept 30, whose salary is greater than or equal to 15,000. (Note: with logical operators - AND precedes OR)

Using the ORDER BY statement to control the display order of selected records

ORDER BY

column1, column2, etc ASC/DESC;

or

ORDER BY

n;

(being the nth column)

Note: The default ordering is ascending. Null values are always displayed first regardless of sort sequence.

A14

Display the employee number, current job and salary of all those who work in Department 30, with the output in ascending salary order.

A15

Display the employee name and current job of all those who work in Department 30, with the output in descending salary order.

A16

Display the employee name and current job of all those who work in Department 30, with the output in descending salary order within each job.

A17

Display employee details for departments 10 and 30, in name order, within each department

NULL Values

If a column has no value for any particular row, it is referred to as a NULL value. This is not the

same as a zero in a numeric column, or a space in a character column.

In MS-SQL Server, the IsNull function can be used to convert a null into a specified value e.g. IsNull(COMM, 0) will return the actual value of COMM if it has a value, or a zero if COMM is null. This is often necessary when performing calculations, or formatting for output since null values will be totally ignored by many functions and operations.

will be totally ignored by many function s and operations. Oracle has a function called NVL

Oracle has a function called NVL which allows you do a similar thing. It actually returns the first non-null value in a list, but used as below enables a null to be treated as a specific number:

Select ename NVL(comm,0) from emp;

A column can be tested using IS NULL or IS NOT NULL e.g.

SELECT

A18

Sales Department?

are

What

FROM

the

A19 Write statements

to

WHERE column_name IS NOT NULL;

highest

and

lowest

incomes

(i.e.

to

include

commission)

in

the

a) Show all the records from table EMPLOYEE

b) Show all the employees who’s job is ‘CLERK

c) Display the no of employees who are earning commission more then 1000.

d) Display name and HIREDATE of the employees whos name starts with a’ and has ‘e’ as second last character.

e) Display Gross Salary of each employee along with employee’s name (hint: gross salary =

sal + comm).

Kamran Shaukat Dar Lecturer IT

BBA VII Semester

Database Management System

Assignment# 2

f) Display all the different job titles, which currently exist in the company.

g) Display the department and number of employees in departments with fewer than 6 employees.

h) How many people are there in each type of job in each department?

i) Find the employee name and its salary who is earning maximum salary in

department j)

Display the no of employees in each department

Kamran Shaukat Dar Lecturer IT