ICA 3
Files and setup
- Download
weather_stations.dbfrom the course-material repository. - Open the database in DB Browser for SQLite
Database reference
The assignment uses the STATION_DATA table.
| Column | Stored data |
|---|---|
station_number |
Weather-station identifier |
report_code |
Report identifier or code |
year, month, day |
Observation date components |
dew_point |
Dew-point measurement |
station_pressure |
Station-pressure measurement |
visibility |
Visibility measurement |
wind_speed |
Wind-speed measurement |
temperature |
Temperature measurement |
precipitation |
Precipitation measurement |
snow_depth |
Snow-depth measurement |
fog, rain, hail, thunder, tornado |
Weather indicators stored as 1 for true and 0 for false |
Use the measurement values in the units in which they are stored in the database. You do not need to convert units.
Part A
Select every column and the first 10 rows from
STATION_DATA.Select only
station_number,year,month,day, andtemperaturefromSTATION_DATA.Select
station_number,report_code,precipitation,rain, andthunder. Renameprecipitationasprecip_amountin the query output.
Part B
Return
station_number,year,month,day, andtemperaturefor observations recorded in the year 2000.Return the date columns,
station_number, andprecipitationfor observations from 2000 through 2009, inclusive, that recorded precipitation greater than zero.Return
station_number, the date columns,dew_point, andstation_pressurefor records in which bothdew_pointandstation_pressureare not missing. Limit the query to observations from June, July, or August.
Part C
Return
station_number, the date columns, andprecipitation. Sort the results from the greatest precipitation to the least precipitation and display only the first 20 rows.Return
station_number, the date columns, andtemperature. Sort first bystation_numberin ascending order and then by date from newest to oldest.
Part D
Count the number of observations in each year. Name the count
observation_countand return one row per year.For each calendar month, calculate the average, minimum, and maximum temperature. Use clear aliases for all three calculated columns.
For each
station_number, count the number of records that have precipitation greater than zero. Name the countprecipitation_report_count.
Part E
Group the data by year and count the number of records in which
tornado = 1. Keep only years with at least one tornado record. Sort the year with the greatest count first.Count the number of observations for each
station_number. Keep only stations with at least 10 observations and sort from the largest count to the smallest count.For each year and month, calculate the average wind speed and count the nonmissing wind-speed values. Keep only groups that have at least 20 nonmissing wind-speed values. Sort the results by year and then month, both in ascending order.
Part F
- Write one query that uses
SELECT,WHERE,GROUP BY,HAVING, andORDER BY.
Your query must:
- use only records from 2000 through 2009, inclusive;
- exclude records with missing precipitation;
- group the remaining records by year and month;
- calculate total precipitation and name it
total_precipitation; - keep only year-month groups whose total precipitation is greater than 5; and
- sort from the greatest total precipitation to the least.