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

008tesdatabase Doct

The document contains SQL queries to retrieve information from tables in a university database. The tables include information about departments, courses, instructors, sections, and what instructors teach. Queries are provided to find instructor names and departments, courses taught by instructors, averages salaries by department, and updating instructor salaries.

Uploaded by

tesewaka3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

008tesdatabase Doct

The document contains SQL queries to retrieve information from tables in a university database. The tables include information about departments, courses, instructors, sections, and what instructors teach. Queries are provided to find instructor names and departments, courses taught by instructors, averages salaries by department, and updating instructor salaries.

Uploaded by

tesewaka3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MEKELLE UNIVERSITY

SCHOOL OF COMPUTING
Database GROUPE ASSIGNMENENT
SECTION-1
NAME ID

TESFAY HAFTU UGR/170036/12

SANAKREAM DANIEL UGR/178255/12

FURTUNA HAGEZOM UGR/179283/12

YARED G.SLASE UGR/179223/12

KIBROM BIRHANE UGR/178600/12

YOHANS GEBREGERGS UGR/178418/12

ARDON UGR/
CREATE TABLE department (

dept_name VARCHAR(20),

building VARCHAR(15),

budget MONEY,

PRIMARY KEY (dept_name)

);

CREATE TABLE course (

course_id VARCHAR(7),

title VARCHAR(50),

dept name VARCHAR(20),

credits NUMERIC(2,0),

PRIMARY KEY (course_id),

FOREIGN KEY (dept_name) REFERENCES department

);

CREATE TABLE instructor (

ID VARCHAR(5),

salary NUMERIC (8,2),

dept_name VARCHAR(20),

PRIMARY KEY (ID),

FOREIGN KEY (dept_name) REFERENCES department

);

CREATE TABLE section (

course_id VARCHAR(8),

sec_id VARCHAR(8),

semester VARCHAR (6),


year NUMERIC(4,0),

building VARCHAR(15),

room_number VARCHAR(7),

time_slot_id VARCHAR(4),

PRIMARY KEY (course_id, sec_id, semester, year),

FOREIGN KEY (course_id) REFERENCES course

);

CREATE TABLE teaches (

ID VARCHAR (5),

course_id VARCHAR (8),

sec_id VARCHAR (8),

semester VARCHAR (6),

year NUMERIC(4,0),

PRIMARY KEY (ID, course_id, sec_id, semester, year),

FOREIGN KEY (course_id, sec_id, semester, year) REFERENCES section,

FOREIGN KEY (ID) REFERENCES instructor

);

1.

Find the names of all instructors.

SELECT name

FROM instructor;

2.

Find the department names of all instructors.


SELECT dept_name

FROM instructor;

3.

Find the department names of all instructors (eliminate duplicates).

SELECT DISTINCT dept_name

FROM instructor;

4.

Find the names of all instructors in the Computer Science department who have salary greater than
$70,000.

SELECT name

FROM instructor

WHERE dept_name = 'Computer Science' AND salary > 70000;

5.

Retrieve the names of all instructors, along with their department names and department building
names.

SELECT instructor.name, instructor.dept_name, department.building

FROM instructor, department

WHERE instructor.dept_name = department.dept_name;

6.

For all instructors in the university who have taught some course, find their names and the course ID of
all courses they taught.

SELECT instructor.name, teaches.course_id

SELECT instructor.name, teaches.course_id

FROM instructor JOIN teaches ON instructor. ID = teaches. ID;

7.
Find the names of all instructors who earn more than the lowest paid instructor in the Information
Systems department.

SELECT name

FROM instructor

WHERE salary > (

SELECT MIN(salary)

FROM instructor

WHERE dept_name = 'Information Systems'

);

8.

List in alphabetical order all instructors in the Physics department.

SELECT name

FROM instructor

FROM instructor

WHERE dept_name = 'Physics'

ORDER BY name ASC;

9.

List the entire instructor relation in descending order of salary.

SELECT *

FROM instructor

ORDER BY salary DESC;

10.

Find the names of instructors with salary amounts between $10,000 and $20,000.
SELECT name

FROM instructor

WHERE salary BETWEEN 10000 AND 20000;

11.

Find all instructors who appear in the instructor relation with null values for salary. SQL

SELECT *

FROM instructor

WHERE salary IS NULL;

12.

Find the average salary of all instructors.

SELECT AVG(salary)

FROM instructor;

13.

Find the average salary of instructors in the Computer Science department.

SELECT AVG(salary)

FROM instructor

WHERE dept_name = 'Computer Science';

14.

Find the total number of instructors who teach a course in the Spring 2016 semester.

SELECT COUNT(DISTINCT teaches. ID)

FROM teaches JOIN section ON teaches.course_id = section.course_id AND teaches.sec_id =


section.sec_id

WHERE semester = 'Spring' AND year = 2016;


15.

Find the average salary in each department.

SELECT dept_name, AVG(salary)

FROM instructor

GROUP BY dept_name;

16.

Retrieve only those departments where the average salary of the instructors is more than $45,000.

SELECT dept_name

FROM instructor

GROUP BY dept name

GROUP BY dept_name

HAVING AVG(salary) > 45000;

17.

Suppose that annual salary increases are being made, and salaries of all instructors are to be increased
by 5 percent.

UPDATE instructor

SET salary = salary * 1.05;

18.

How about if a salary increase is to be paid only to instructors with salary of less than $20,000.

UPDATE instructor

SET salary salary * 1.05

WHERE salary < 20000;

19.
Let us now suppose that all instructors with salary over $100,000 receive a 3 percent raise, whereas all
others receive a 5 percent raise.

UPDATE instructor

18.

How about if a salary increase is to be paid only to instructors with salary of less than $20,000.

UPDATE instructor

SET salary = salary * 1.05

WHERE salary < 20000;

19.

Let us now suppose that all instructors with salary over $100,000 receive a 3 percent raise, whereas all
others receive

a 5 percent raise.

UPDATE instructor

SET salary =

CASE

WHEN salary > 100000 THEN salary * 1.03

ELSE salary * 1.05

END;

You might also like