我们可以用通常的关系查询选择和映射查询检索 weather 表. 我们可以用一个 SQL SELECT 语句干这件事. 该语句分成目标列表(列出返回字段的部分)和条件(限制条件部分). 例如,我们检索weather表中的所有行,键入:
SELECT * FROM weather;输出应该是:
+--------------+---------+---------+------+------------+ |city | temp_lo | temp_hi | prcp | date | +--------------+---------+---------+------+------------+ |San Francisco | 46 | 50 | 0.25 | 1994-11-27 | +--------------+---------+---------+------+------------+ |San Francisco | 43 | 57 | 0 | 1994-11-29 | +--------------+---------+---------+------+------------+ |Hayward | 37 | 54 | | 1994-11-29 | +--------------+---------+---------+------+------------+你可以在目标列表中输入任意的表达式.例如:
SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date FROM weather;
在任何查询条件中条件都可以使用任意布尔操作符 (AND,OR 和 NOT)例如,
SELECT * FROM weather WHERE city = 'San Francisco' AND prcp > 0.0;结果是:
+--------------+---------+---------+------+------------+ |city | temp_lo | temp_hi | prcp | date | +--------------+---------+---------+------+------------+ |San Francisco | 46 | 50 | 0.25 | 1994-11-27 | +--------------+---------+---------+------+------------+
最后,你可以对 select 的结果 排序输出或去除 重复记录.
SELECT DISTINCT city FROM weather ORDER BY city;