Displaythe list of all the one-way
connections between two cities for which the population of one of the 2
cities is lower than 80000 inhabitants.
Links
between tables
Besides the links define above, it is
necessary to check that the string "V1.Ville+V.Ville " is not in the
table "Distances", because that would mean that connection between the
2 cities is a double-ways connexion. This condition is checked in the
nested Select clause.
Displaythe list of cities, which
can be distant from 4 road sections (there can indeed be shorter
connections into 2 or 3 sections), and the distance which separates
them.
Links
between tables
SQL query
We reach here the limits of the SQL
language because this language is not recursive and the general
treatment of question of this type implies a broad recourse to
recursivity.
Display the number of inhabitants by region
and department. We suppose that the population of a region is that of
the cities which are a part of the road network.
Display the name of the region which has
the longest road network and the number of kilometers of this network.
To treat this question it is necessary to
create 2 requests :
6.1-A request of creation of a work
table "WorkTable" composed of the attributes: Numregion, Nomregion and
Distance for all double-ways connections, between 2 cities of the same
region.
This request is linked by a "UNION" predicat to another query which
adds to the preceding one all the one-way connections between 2 cities
of the same region.
6.2-A request of selection, starting from
the table "WorkTable" created above.
Links
between tables (requête 6.1)
SQL query
6.1
CREATE VIEW WorkTable(Numregion, Nomregion, Distance) AS SELECT R.numregion, R.Nomregion, Sum(D.Distance)/2 FROM Distances D, Villes V, Villes V1, Departement
P, Departement P1, Region R, Region R1 WHERE D.Villedepart=V.Ville AND V.Numdept=P.Numdept AND P.Numregion=R.numregion AND D.Villearrivee=V1.Ville AND V1.Numdept=P1.Numdept AND P1.Numregion=R1.numregion AND R.Numregion=R1.Numregion AND D.villedepart IN
(SELECT villearrivee FROM
Distances WHERE D.villearrivee=villedepart) GROUP BY R.Numregion, R.Nomregion UNION SELECT R.numregion, R.Nomregion, Sum(D.Distance) FROM Distances D, Villes V, Villes V1, Departement
P, Departement P1, Region R, Region R1 WHERE D.Villedepart=V.Ville AND V.Numdept=P.Numdept AND P.Numregion=R.numregion AND D.Villearrivee=V1.Ville AND V1.Numdept=P1.Numdept AND P1.Numregion=R1.numregion AND R.Numregion=R1.Numregion AND D.villedepart NOT IN
(SELECT villearrivee FROM
Distances WHERE D.villearrivee=villedepart) GROUP BY R.Numregion, R.Nomregion;
Links
between tables (requête 6.2)
SQL query
6.2 The first line of the next query gives the answer to
the question.
SELECT W.numregion, W.Nomregion, Sum(W.Distance)
AS "Longueur du réseau" FROM WorkTable AS W GROUP BY W.numregion, W.Nomregion ORDER BY 3DESC;