

# 步骤 3：查询数据
<a name="step-3-query-data"></a>

现在，您已根据 Amazon S3 中的数据在 Athena 中创建了 `cloudfront_logs` 表，您可以针对该表运行 SQL 查询，并在 Athena 中查看结果。有关在 Athena 中使用 SQL 的更多信息，请参阅 [Athena 的 SQL 参考](ddl-sql-reference.md)。

**运行查询**

1. 选择加号(**\$1**)以打开新的查询选项卡，然后在查询窗格中输入以下 SQL 语句。

   ```
   SELECT os, COUNT(*) count 
   FROM cloudfront_logs 
   WHERE date BETWEEN date '2014-07-05' AND date '2014-08-05' 
   GROUP BY os
   ```

1. 选择**运行**。

   结果与以下内容类似：  
![\[在 Athena 控制台中查看查询结果。\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/images/getting-started-query-results.png)

1. 要将查询结果保存到 `.csv` 文件，选择 **Download results**（下载结果）。  
![\[以 CSV 格式下载查询结果。\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/images/getting-started-query-results-download-csv.png)

1. 要查看或运行之前的查询，选择 **Recent queries**（最近的查询）选项卡。  
![\[选择 Recent queries（最近的查询）以查看以前的查询。\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/images/getting-started-recent-queries.png)

1. 要从 **Recent queries**（最近的查询）选项卡下载以前查询的结果，请选择查询，然后选择 **Download results**（下载结果）。查询保留 45 天。  
![\[在 Athena 控制台中查看和下载最近的查询。\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/images/getting-started-recent-queries-tab-download.png)

1. 要将一个或多个最近的 SQL 查询字符串下载到 CSV 文件，请选择 **Download CSV**（下载 CSV）。  
![\[将最近的查询字符串下载到 CSV 文件。\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/images/getting-started-recent-queries-tab-download-csv.png)

   有关更多信息，请参阅 [使用查询结果和最近查询](querying.md)。