Worksheet Two

Start by ensuring that the world database used in the first lab is correctly installed.

Using at most one SQL query per question, find the answers to the following questions and submit them, one answer per line, in a text file that you submit using cssubmit.

Your query does not have to produce the answer and only the answer - for example, you can write a query that produces a table that contains the answer and then read it off. However you should avoid using one query to find one thing (say a CountryCode) and then using that information in a second query.

All questions are to be answered just according to the data in the database, regardless of how out-of-date it is!

Some (but not all) of the questions will require more than one table, so you should use an appropriate JOIN. The first thing to do with each question is to decide which tables contain the information you need - thus if the question is asking about capital cities, then this information is only in Country. Use only the tables you need and no more!

One final hint: remember the SQL mantra of construct (construct the candidate rows as an appropriate Cartesian product), then filter (extract only the rows that make sense and contain the information you want) and finally project (extract only the columns you want).

 +----------------------+------------+
| Name                 | Language   |
+----------------------+------------+
| Aruba                | Dutch      |
| Afghanistan          | Dari       |
| Afghanistan          | Pashto     |
| Anguilla             | English    |
+----------------+---------------------------+
| Name           | Region                    |
+----------------+---------------------------+
| Kabul          | Southern and Central Asia |
| Qandahar       | Southern and Central Asia |
| Herat          | Southern and Central Asia |
| Mazar-e-Sharif | Southern and Central Asia |
| Amsterdam      | Western Europe            |
| Rotterdam      | Western Europe

Written with StackEdit.