Edb3 DAY: Monday Date: May 13th, 2019 Time: 16:15 - 18:15
Edb3 DAY: Monday Date: May 13th, 2019 Time: 16:15 - 18:15
MODULE : EDB3
DAY : Monday
Module EDB3
Supervisor KHST
Distribution of points:
Exercise 1 2 3 4 5 6 7 8 Total
Points 18 12 12 12 12 12 12 10 100
Number of pages: 6
Remarks:
- Do not forget to state your name, student number and class inside the text file!
- For SQL queries that do not run successfully in SQL developer (i.e. generating errors),
no points will be given.
- All code must be properly indented. Points will be withdrawn for each solution that
isn’t indented!
Success!
Page 1 of 6
EDB3 Exam, May 13th 2019
Exercise 1 to 7:
1. [18p] Create a view candidatesWithNarrowWin that gives the election years, the
candidates that won the elections in those years and the number of gained votes of
the winning candidates, for those election years where there were exactly two
candidates and the difference between the number of gained votes of the winner
and the number of gained votes of the loser was smaller than 10. Rename the
columns of the view to electionYear, winningCandidateName, winningNrOfVotes.
2. [12p] Give the president names, parties, years of service and death ages of the
presidents, that served the smallest amount of years of presidents of their party, and
that died younger than the average age of death of presidents of their party.
3. [12p] Give the administration numbers, president names and years of inauguration
of the presidents that were inaugurated after 1900 and were both president and vice
president in administrations with the same administration number (for example
president COOLIDGE C was first vice president and later president in
administrations with administration number 34). The results must be in ascending
order of administration number.
4. [12p] Give the president names, years of birth, states of birth and the years their
states of birth entered the United States. Give all these details only when the year
entered for the state was 1845 or later and the president won all the elections he
was candidate for.
5. [12p] Give the president names and the hobbies of the presidents that served for at
least 5 years, and were married two or more times and had children from all the
marriages. If the president does not have hobbies “no hobbies” must be given.
6. [12p] Give the president names and years of service, for the presidents that were
born in the state(s) where the most presidents were born.
Page 2 of 6
EDB3 Exam, May 13th 2019
7. [12p] Create a query that displays the following output: for each age of the president
at the marriage, the number of presidents married at that age, the number of
presidents married at that age with a spouse with the same age and the number of
presidents married at that age with a spouse with a different age must be given.
For example:
18 1 0 1
20 2 0 2
21 1 0 1
22 2 0 2
23 2 0 2
24 2 0 2
25 3 0 3
26 6 2 4
27 3 0 3
28 7 0 7
29 3 0 3
30 2 0 2
31 2 2 0
33 2 0 2
35 2 0 2
36 1 0 1
41 1 0 1
43 1 0 1
49 1 0 1
54 1 0 1
58 2 0 2
62 1 0 1
Exercise 8 [10p]
ON e.manager_id = m.employee_id;
Page 3 of 6
EDB3 Exam, May 13th 2019
Appendix 1: The “Presidents” Database
The Create Table statements for this database and the Alter Table statements for creation of
the foreign key constraints for this database are provided on the next pages.
Page 4 of 6
EDB3 Exam, May 13th 2019
Attribute Datatype Description
CONSTRAINT CHECK_WIN_LOS
CHECK (WINNER_LOSER_INDIC = 'W' OR WINNER_LOSER_INDIC = 'L'),
CONSTRAINT PRIM_KEY_ELEC PRIMARY KEY (ELECTION_YEAR,CANDIDATE)
);
Page 5 of 6
EDB3 Exam, May 13th 2019
Attribute Datatype Description
);
END of EXAM
Page 6 of 6
EDB3 Exam, May 13th 2019