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

Polytechnic of Namibia

School of Information Technology


Department of Software Engineering
Private Bag 13388, 13 Storch Street, Windhoek, Namibia Tel: +264-(0)61-207-2052 Fax: +264-(0)61-207-2051

Subject Code: Subject: Semester: Date Published:

IDB220S Introduction to Databases 1 B 1st Semester 2012 6 March, 2012

Assignment #: 1 Topic: Data manipulation (Lesson 1 - 4)

Instructions
1. This is Assignment (Nr. 1 of 2) and contributes 10% to your semester mark for this course.

2. The deadline for this assignment 1 is: Monday 19th March 2012 23:59 Hrs.

3. Please feel free to contact Mr. Colin Stanley if you have any questions or problems regarding

this assignment.
4. Students will not be reminded about outstanding assignments. All assignment s not handed in

time will be marked with 0%.


5. This assignment should be done individually and proper SQL coding is mandatory such

comments, indentations, SQL keywords in uppercases, etc.


6. Academic Honesty and Integrity of the Polytechnic of Namibia (as found in the undergraduate

prospectus 2011, AC3.2 page 22) is fully applicable to this assignment.

This assignment paper consists of 4 pages (including the front page).

Page 2 of 5

1. Assignment Scenario
Imagine that you are employed as a Database Developer at the Windhoek Community Service Organisation (W.C.S). The main role of this organisation to is to help families to find people who can take care of their old or sick relatives. WCSs database has the following four tables:

Families stores the general information about the individual families Contact_persons stores the old or sick relative details of the families Needs stores the general requirements specified by the old or sick relative that the helper or care taker should fulfil Care_takers stores the information about those people (care takers) willing to assist the old or sick the people of the families

2. Database Schema Setup


2.1 Load and execute the schema file titled IDB220S_Assignment1.sql 2.2 Write an SQL statement that would display all the tables inside the database. [1 Mark] 2.3 Write an SQL statement that would provide information about the families table structure. [1 Mark] 3 [0 Mark]

Write SQL statements that would perform the following:


3.1 That displays the family id, name, street address and location of all those families who has a

surname that has the letter z has the second letter and ends with the letter e and stays in Windhoek north. [5 Marks]
SELECT family_id AS "Family ID", first_name AS "Name", street_address AS "Street Address", location FROM families WHERE surname LIKE '_z%e' and LOWER(location) LIKE LOWER('Windhoek north'); 2 marks for all columns specified and 1 mark for proper use of alias 1 mark for the surname pattern search 1 mark for location search (if string is as used as specified than lower function should be used)

Page 3 of 5

3.2 That displays the old or sick person name, sickness details and the language they speak

Kwanyama, Diriku and Nama. The information should be sorted in descending order by the persons name. [5 Marks]
SELECT first_name "Sick Person Name", sickness "Sickness", language_spoken "Language Spoken" FROM contact_persons WHERE language_spoken IN ('Kwanyama', 'Diriku', 'Nama') ORDER BY 1 desc; 2 marks for all columns specified and 1 mark for proper use of alias 1 mark for the language condition 1 mark for family surname ORDER BY clause 3.3 That will concatenate the care takers name with his or her qualification, in between there

should be a string has a and append the string degree at the end of the concatenation, the column should read as Qualification. Also displays the age and its category using a case expression as follows; age in the range of 17 to 19 as Teenage, 20 to 30 as Lady or Gentlemen and above or below the specified range as Adolescent or Elderly, the resulted column should read as Age Category. [10 Marks] The table 1 below depicts the sample result:
Table 1 QUALIFICATION Nokuthula has a Nursing degree Kelly has a Nursing degree Megan has a Nurse Practitioner degree Robyn has a Nurse Practitioner degree Hannah has a Nurse Practitioner degree Ina-Cherie has a First Aid degree Lil has a First Aid degree AGE 21 25 30 18 18 19 20 Age Category Lady or Gentlemen Lady or Gentlemen Lady or Gentlemen Teenage Teenage Teenage Lady or Gentlemen

SELECT INITCAP(first_name) || ' has a ' ||qualification || ' degree ' AS Qualification, age, (CASE WHEN age BETWEEN 17 AND 19 THEN 'Teenage' WHEN age BETWEEN 20 AND 30 THEN 'Lady or Gentlemen' ELSE 'Adolescent or Elderly' END) "Age Category" FROM care_takers; 2 marks for all the columns specified and 1 mark for proper use of alias 1 mark for initcap for first name 6 marks for the correct use of the case expression Page 4 of 5

3.4 Displays the surname, nationality and qualification all those care takers that still have not

started working
SELECT surname, nationality, qualification FROM care_takers WHERE start_date IS NULL; 1 mark all the columns specified and 2 marks for the start date condition

[3 Marks]

3.5 Using a variable Work_StartDate write an SQL statement that would select the sick

needs specification of week days, age and start date from needs that started working before or on the value of Work_StartDate that you defined. [3 Marks]
DEFINE Work_StartDate = '01-MAR-12' SELECT weekday, age, start_date FROM needs WHERE start_date <= '&Work_StartDate'; 1 mark for defined variable, 1 mark all the columns specified and 1 mark for the where condition

3.6 That display the average age for every language spoken from the family needs table.
[2 Marks] SELECT LANGUAGE_SPOKEN, AVG(age) FROM needs GROUP BY LANGUAGE_SPOKEN; 1 mark for columns specified including use of average function and 1 mark for group by clause TOTAL [30]

4 Deliverable guidelines:
4.1 All your SQL solution statements should be saved in one script file name as your student

number e.g. 200229338.sql.


4.2 This script should be able to run on both iSQLPlus and SQLPlus environment without the

lecturer modifying anything.


4.3 Two copies of this file should be submitted, one as a soft copy to be saved in IDB220S

Assignment 1 folder (should have your student number as well) and another one as a hard copy to your group lecturer. 4.4 No email submission would be accepted.

Page 5 of 5

Вам также может понравиться