SQL TUTORIALS

Common Keywords Exercise Answer Key

Answer Key

  1. 12 earthquakes occurred in Northern California with a magnitude between 6.0 and 7.0. Query used:
    SELECT DISTINCT *
    FROM earthquake
    WHERE place LIKE '%Northern California%' AND magnitude BETWEEN 6.0 AND 7.0;
  2. The deepest earthquake that occurred in either Utah, Oregon, Wyoming, or Egypt was 21.5 meters deep. Query used:
    SELECT MAX(depth) AS max_depth
    FROM earthquake
    WHERE place IN('Utah', 'Oregon', 'Wyoming', 'Egypt');
  3. There are 0 NULL values in the "place" column. Query used:
    SELECT COUNT(*)
    FROM earthquake
    WHERE place IS NULL;
  4. There are 978 places that either start with an "A" or end with an "r". Query used:
    SELECT DISTINCT COUNT(*)
    FROM earthquake
    WHERE place LIKE 'A%' OR place LIKE '%r';
  5. The average depth for all earthquakes that occurred between 1/1/1970 and 1/1/1990, had a magnitude of at least 6.0 and were caused by an earthquake is 69.83 meters. Query used:
    SELECT AVG(depth) AS avg_depth
    FROM earthquake
    WHERE occurred_on BETWEEN '1/1/1970' AND '1/1/1990' AND magnitude >= 6.0 AND cause = 'earthquake';