Structured Data: Create A Table To Store Information About Weather Observation Stations
Structured Data: Create A Table To Store Information About Weather Observation Stations
Accessing structured data with SQL is quite different from the full
text search of documents on
the Web. Structured data in the relational
model means data that can be represented in tables -
- rows and columns.
Each row in a table represents a different object, and the columns
represent
various "attributes" of the object. The columns have names and integrity
constraints
that specify valid values.
Since the column values are named and are represented in a consistent
format, you can select
rows very precisely, based on their contents. This
is especially helpful in dealing with numeric
data. You can also join together
data from different tables, based on matching column values.
You can do
useful types of analysis, listing objects that are in one table and missing
(or present,
or have specific attributes) from a related table. You can
extract from a large table precisely
those rows of interest, regrouping
them and generating simple statistics on them.
creating a table
creating a view
inserting rows
updating rows
deleting rows
commit -- making changes permanent
rollback -- undoing temporary changes
enforcing integrity constraints
using an Embedded C program
CITY CHAR(20),
STATE CHAR(2),
LAT_N REAL,
LONG_W REAL);
ID CITY STATE
44 Denver CO
66 Caribou ME
create another table to store normalized temperature and precipitation
data:
-- rainfall is in inches.
populate the table STATS with some statistics for January and July:
query to look at the table STATS, ordered by month and greatest rainfall,
with columns
rearranged:
FROM STATS
WHERE MONTH = 7
ORDER BY TEMP_F;
LAT_N CITY TEMP_F
47 Caribou 65.8
40 Denver 74.8
33 Phoenix 91.7
FROM STATS
GROUP BY ID;
MAX(TEMP_F) MIN(TEMP_F) AVG(RAIN_I) ID
91.7 57.4 2.73 13
74.8 27.3 1.145 44
65.8 6.7 3.31 66
-- rows are selected from the STATION table based on related values
in the STATS table.
SELECT ID,
MONTH,
RAIN_I * 0.3937
FROM STATS;
query to look at table STATS in a metric light (through the new view):
ORDER BY RAIN_C;
ID MONTH TEMP_C RAIN_C
44 1 -2.6111111 .070866
66 1 -14.055556 .82677
WHERE ID = 44
AND MONTH = 7;
COMMIT WORK;
WHERE ID = 44;
ROLLBACK WORK;
WHERE ID = 44
AND MONTH = 7;
COMMIT WORK;
-- note that we use longitude values from the related STATION table
to determine which STAT
stations were east of 90 degrees.
WHERE MONTH = 7
COMMIT WORK;