Professional Documents
Culture Documents
Exercise#1
Herearethedatacontainedinthetablesofarelationaldatabase,followedbyaSQLquerytobeexecuted
onthisdatabase.Whatwillbethedatatableresultingfromtheexecutionofthisquery?Pleasecompletethe
table below by watching to entitle the columns properly. Be sure to briefly explain your reasoning or to
detailtheintermediatesteps.Anyresponsenotorpoorlyjustifiedwillbeconsideredasnull.
Tableclients
Tablesales
2
4
2
7/07/2012
Tableproducts
3
4
4
1/05/2011
1
1
2
26/03/2012
p_id
p_name
p_category p_price
5
2
1
28/03/2011
1
Milou
Animals
100
2
2
1
1/06/2011
2
Cheval
Animals
500
3
4
Combinaison
Jeans
Clothes
Clothes
200
100
Requte
SELECT Year([v_date]) AS Year, p_category AS Category,
SUM([p_price]*[v_quantity]) AS Amount FROM products, clients, sales WHERE c_id =
v_client AND p_id = v_product AND NOT c_country="France" GROUP BY YEAR([v_date]),
p_category UNION SELECT Year([v_date]) AS Year, "Sum" AS Category,
SUM([p_price]*[v_quantity]) AS Amount FROM products, clients, sales WHERE c_id =
v_client AND p_id = v_product AND NOT c_country="France" GROUP BY YEAR([v_date]),
"Sum" ORDER BY Year, Category;
SOLUTION:
Year
Category
Amount
2011
2011
2011
2012
2012
2012
Animals
Clothes
Sum
Animals
Clothes
Sum
1100
700
1800
200
800
1000
PROF.N.VANZEEBROECKFALL2014
GESTS482OPERATIONSANDDIGITALBUSINESSSQLEXERCISES
Exercise#2
Herearethedatacontainedinthetablesofarelationaldatabase,followedbyaSQLquerytobeexecuted
onthisdatabase.Whatwillbethedatatableresultingfromtheexecutionofthisquery?Pleasecompletethe
table below by watching to entitle the columns properly. Be sure to briefly explain your reasoning or to
detailtheintermediatesteps.Anyresponsenotorpoorlyjustifiedwillbeconsideredasnull.Notethatthe
tablebelowmayprovidemorelinesorcolumnsthanwhattheexactanswerrequires.
Tableclients
Tablereservations
id_client
name
Country
id_client id_room
date
nb_nights
1
Gassner
USA
1
1
1/02/2013
2
2
Dewatripont Belgium
1
2
3/03/2013
3
3
vanZeebroeck Belgium
2
3
1/12/2012
5
4
Tudor
USA
3
2
15/01/2013
1
4
1
16/05/2013
4
TableRooms
3
3
20/07/2013
3
id_room nb_beds price
1
2
100
2
1
80
3
2
150
Requte
SELECT Beds, Amount AS Volume, Nunber AS Frequency, Amount/Number AS Average FROM
(SELECT nb_beds AS Beds, SUM([nb_nights]*[price]) AS Amount, SUM(1) AS Number
FROM clients, reservations, rooms WHERE rooms.id_room = reservations.id_room AND
clients.id_client = reservations.id_client AND Year([date])=2013 GROUP BY
nb_beds)ORDER BY Beds;
SOLUTION:
Beds
Volume
Frequency
Average
1
2
320
1050
2
3
160
350
PROF.N.VANZEEBROECKFALL2014
GESTS482OPERATIONSANDDIGITALBUSINESSSQLEXERCISES
Exercise#3
Herearethedatacontainedinthetablesofarelationaldatabase,followedbyaSQLquerytobeexecuted
onthisdatabase.Whatwillbethedatatableresultingfromtheexecutionofthisquery?Pleasecompletethe
table below by watching to entitle the columns properly. Be sure to briefly explain your reasoning or to
detailtheintermediatesteps.Anyresponsenotorpoorlyjustifiedwillbeconsideredasnull.Notethatthe
tablebelowmayprovidemorelinesorcolumnsthanwhattheexactanswerrequires.Notethatthefunction
Dates()sendbackthedateoftheday,i.e.28/05/2014,andthatitispossiblethatthetableprovidedforthe
responsecontainsmorelinesorcolumnsthanwhattheexactanswerrequires.
TableWork
TableReader
o_id o_title
o_type
1
2
3
4
5
6
7
Unbearablelightnessofthebeing
Thefoundationsofcomputing
Nostalgia,omydelices
Thefoundationsofcomputing
Thehumancondition
FateandtheNecessity
ScienceandHypothesis
Novel
Scientist
Shortstories
Scientist
Novel
Essay
Essay
l_id
1
2
3
4
l_name
NadgeFantasque
FranceLesoir
JrmyMonlivre
BrunoLelit
l_type
Student
Prof
Prof
Student
TableLoan
Requte
SELECT o_type AS Group, COUNT(e_id) AS Number, SUM(Date()-(e_date+e_duration)) AS
Days FROM Work, Loan WHERE o_id = e_work AND e_id IN (SELECT e_id FROM Loan WHERE
e_return=0 AND (Date()-(e_date+e_duration))>0) GROUP BY o_type ORDER BY
COUNT(e_id) DESC, o_type;
SOLUTION:
Group
Number
Days
Novel
Scientist
Essay
2
2
1
8
6
2
PROF.N.VANZEEBROECKFALL2014
GESTS482OPERATIONSANDDIGITALBUSINESSSQLEXERCISES
Exercise#4
DownloadandopentheAccessDBnamedStudents.mdb.PleasecreatethefollowingSQLqueriesandrun
themonthedata.
1. Displaythelistofstudents
2. Displaythenameandfirstnameofstudents<20years
3. Displaystudentswhosenamebeginwith"Ma"
4. Displaystudentssortedoutbydecreasingage
5. Displaytheaverageratingpercourse
6. Displaythetranscriptofeachstudent
7. Displaytheaverage,minandmaxofeachstudentstudentssortedoutalphabetically
8. DisplaytheratingsofECONS202lowerthantheaverageofthecourse
9. Displaystudentswithanaveragecorrespondingto"honors"(distinction)(i.e.average>=12and<14)
10. Insertanewcourse(INFOS203)inthetableCourses
11. InsertallthestudentsinthetableRatingsforthisnewcourse
12. Give12toallstudentsforthisnewcourse
13. Add1pointincomputingforallstudents
14. Raisethecomputing'sgradeofthestudentswhofailed(<10)
15. Deletetheaddedcourse
Whatistheissueraisedbythelastquery?andhowtosolveit?
SOLUTIONS:
1.Displaythelistofstudents
SELECT *
FROM students
2.Displaythenameandfirstnameofstudents<20years
PROF.N.VANZEEBROECKFALL2014
GESTS482OPERATIONSANDDIGITALBUSINESSSQLEXERCISES
5.Displaytheaverageratingpercourse
PROF.N.VANZEEBROECKFALL2014
GESTS482OPERATIONSANDDIGITALBUSINESSSQLEXERCISES
12.Give12toallstudentsforthisnewcourse
UPDATE cotes
SET cote=12
WHERE cours="INFOS203"
13.Add1pointincomputingforallstudents
UPDATE cotes
SET cote=cote+1
WHERE cours="INFOS202"
14.Raisethecomputing'sgradeofthestudentswhofailed(<10)
UPDATE cotes
SET cote=10
WHERE cours="INFOS202" AND cote<10
15.Deletetheaddedcourse
DELETE FROM cours
WHERE mnemonique="INFOS203"
PROF.N.VANZEEBROECKFALL2014