Database: storm_record

Question: Show all region code and region name sorted by the codes.
SQL: SELECT region_code ,  region_name FROM region ORDER BY region_code;

Question: List all region names in alphabetical order.
SQL: SELECT region_name FROM region ORDER BY region_name;

Question: Show names for all regions except for Denmark.
SQL: SELECT region_name FROM region WHERE region_name != 'Denmark';

Question: How many storms had death records?
SQL: SELECT count(*) FROM storm WHERE Number_Deaths  >  0;

Question: List name, dates active, and number of deaths for all storms with at least 1 death.
SQL: SELECT name ,  dates_active ,  number_deaths FROM storm WHERE number_deaths  >=  1;

Question: Show the average and maximum damage for all storms with max speed higher than 1000.
SQL: SELECT avg(damage_millions_USD) ,  max(damage_millions_USD) FROM storm WHERE max_speed  >  1000;

Question: What is the total number of deaths and damage for all storms with a max speed greater than the average?
SQL: SELECT sum(number_deaths) ,  sum(damage_millions_USD) FROM storm WHERE max_speed  >  (SELECT avg(max_speed) FROM storm);

Question: List name and damage for all storms in a descending order of max speed.
SQL: SELECT name ,  damage_millions_USD FROM storm ORDER BY max_speed DESC;

Question: How many regions are affected?
SQL: SELECT count(DISTINCT region_id) FROM affected_region

Question: Show the name for regions not affected.
SQL: SELECT region_name FROM region WHERE region_id NOT IN (SELECT region_id FROM affected_region);

Question: Show the name for regions and the number of storms for each region.
SQL: SELECT T1.region_name ,  count(*) FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id;

Question: List the name for storms and the number of affected regions for each storm.
SQL: SELECT T1.name ,  count(*) FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id  =  T2.storm_id GROUP BY T1.storm_id;

Question: What is the storm name and max speed which affected the greatest number of regions?
SQL: SELECT T1.name ,  T1.max_speed FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id  =  T2.storm_id GROUP BY T1.storm_id ORDER BY count(*) DESC LIMIT 1;

Question: Show the name of storms which don't have affected region in record.
SQL: SELECT name FROM storm WHERE storm_id NOT IN (SELECT storm_id FROM affected_region);

Question: Show storm name with at least two regions and 10 cities affected.
SQL: SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id  =  T2.storm_id GROUP BY T1.storm_id HAVING count(*)  >=  2 INTERSECT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id  =  T2.storm_id GROUP BY T1.storm_id HAVING sum(T2.number_city_affected)  >=  10;

Question: Show all storm names except for those with at least two affected regions.
SQL: SELECT name FROM storm EXCEPT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id  =  T2.storm_id GROUP BY T1.storm_id HAVING count(*)  >=  2;