Download SQL

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Tau Ceti wikipedia , lookup

Beta Pictoris wikipedia , lookup

Nebular hypothesis wikipedia , lookup

Super-Earth wikipedia , lookup

Transcript
Lab Session 6
STATS 220 Data Technologies
Due 12:00 Mon 27 April
We will work with the exoPlanets database.
This database contains information on planets that have been discovered outside the solar system.
For each planet, we know the planet name, the name of the star that the planet orbits, the name
of the constellation that the star is in, the year the planet was discovered, the distance of the
planet from the star, the time it takes for the planet to orbit the star, what sort of planet it is,
and how big the planet is.
The first ten planets are shown below (there are many more in the database).
id
name
star constellation year orbital.radius orbital.period
type mass
1
PSR 1257 a
PSR 1257
NA 1991
0.1900
25.2620
Pulsar
NA
2
PSR 1257 b
PSR 1257
NA 1991
0.3600
66.5000
Pulsar
NA
3
PSR 1257 c
PSR 1257
NA 1994
0.4600
98.2000
Pulsar
NA
4
PSR 1257 d
PSR 1257
NA 1994
40.0000
62050.0000
Pulsar
NA
5
51 Pegasi b
51 Pegasi
Pegasus 1995
0.0500
4.2300 Hot Jupiter 0.47
6 Upsilon Andromedae b Upsilon Andromedae
Andromedae 1996
0.0500
4.6200 Hot Jupiter 0.71
7
55 Cancri b
55 Cancri
Cancer 1996
0.1180
14.6600
Gas Giant 0.84
8
47 Ursae Majoris b
47 Ursae Majoris
Ursa Major 1996
2.1000
1095.0000
Gas Giant 2.41
9
tau Boo
tau Bootis
Bootes 1996
0.0462
3.3128 Hot Jupiter 3.87
10
70 Virginis b
70 Virginis
Virgo 1996
0.4300
116.6000
Gas Giant 6.60
The database consists of three tables, with information about constellations and stars stored in
separate tables. The structure of the tables in this database are shown below:
constellation tbl
id constellation
star tbl
id star
planet tbl
id planet
constellation
year
radius
planet_tbl
id
planet
year
radius
period
type
mass
star
period
type
mass
star_tbl
id
star
constellation
●
1
star
●
constellation_tbl
id
constellation
1. Write an SQL query to list the planets discovered in 1991.
+----+------------+------+--------+--------+--------+------+------+
| id | planet
| year | radius | period | type
| mass | star |
+----+------------+------+--------+--------+--------+------+------+
| 1 | PSR 1257 a | 1991 |
0.19 | 25.262 | Pulsar | NULL |
1 |
| 2 | PSR 1257 b | 1991 |
0.36 |
66.5 | Pulsar | NULL |
1 |
+----+------------+------+--------+--------+--------+------+------+
2. Write an SQL query to list only the name, type, and mass of the planets discovered in 1996,
ordered by mass.
+----------------------+-------------+------+
| planet
| type
| mass |
+----------------------+-------------+------+
| Upsilon Andromedae b | Hot Jupiter | 0.71 |
| 55 Cancri b
| Gas Giant
| 0.84 |
| 47 Ursae Majoris b
| Gas Giant
| 2.41 |
| tau Boo
| Hot Jupiter | 3.87 |
| 70 Virginis b
| Gas Giant
| 6.6 |
+----------------------+-------------+------+
3. Write an SQL query to list the planet and year of discovery for planets with Cancri somewhere in their name.
+-------------+------+
| planet
| year |
+-------------+------+
| 55 Cancri b | 1996 |
| 55 Cancri c | 2002 |
| 55 Cancri d | 2002 |
| 55 Cancri e | 2004 |
+-------------+------+
4. Write an SQL query to list the planet and year of discovery and star name for planets with
Cancri somewhere in their name.
+-------------+------+-----------+
| planet
| year | star
|
+-------------+------+-----------+
| 55 Cancri b | 1996 | 55 Cancri |
| 55 Cancri c | 2002 | 55 Cancri |
| 55 Cancri d | 2002 | 55 Cancri |
| 55 Cancri e | 2004 | 55 Cancri |
+-------------+------+-----------+
2
5. Write an SQL query to list the planet and year of discovery and star name and constellation
name for planets with Cancri somewhere in their name.
+-------------+------+-----------+---------------+
| planet
| year | star
| constellation |
+-------------+------+-----------+---------------+
| 55 Cancri b | 1996 | 55 Cancri | Cancer
|
| 55 Cancri c | 2002 | 55 Cancri | Cancer
|
| 55 Cancri d | 2002 | 55 Cancri | Cancer
|
| 55 Cancri e | 2004 | 55 Cancri | Cancer
|
+-------------+------+-----------+---------------+
6. Write an SQL query to list the planet and year of discovery and star name and constellation
name for all planets with OGLE-TR somewhere in their name.
+---------------+------+-------------+---------------+
| planet
| year | star
| constellation |
+---------------+------+-------------+---------------+
| OGLE-TR 56
| 2003 | OGLE-TR-56 | Sagittarius
|
| OGLE-TR-111 b | 2004 | OGLE-TR-111 | NULL
|
| OGLE-TR-132 b | 2004 | OGLE-TR-132 | NULL
|
| OGLE-TR-113 b | 2004 | OGLE-TR-113 | NULL
|
+---------------+------+-------------+---------------+
7. BONUS - NO MARKS
Write an SQL query to list the stars with more than two planets.
+-----------------+--------------------+
| numberOfPlanets | star
|
+-----------------+--------------------+
|
3 | HD 160691
|
|
3 | Upsilon Andromedae |
|
4 | 55 Cancri
|
|
4 | PSR 1257
|
+-----------------+--------------------+
NOTE: You should use SQL SELECT statements to view the contents of the tables (e.g., SELECT
* FROM constellation tbl).
NOTE: To try out queries you should use the form at
http://stat18.stat.auckland.ac.nz/stats220/2008/bin/sqlexoplanetsform.php
There is a link to this form from the “Resources” section of the STATS 220 web site.
NOTE: You should submit your answers via the submission form in the “Submissions” section
of the STATS 220 web site.
3