使用 Google Cloud 控制台查詢公開資料集
瞭解如何使用 Google Cloud 控制台,在 BigQuery 中找出及查詢公開資料集。
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
確認已啟用 BigQuery API。
如果您建立了新專案,系統會自動啟用 BigQuery API。
如果在本教學課程中使用的 Google Cloud 專案未啟用計費功能,您需要在 BigQuery 沙箱中上傳及使用資料。BigQuery 沙箱可讓您學習 BigQuery,但可免費使用的 BigQuery 功能有限。
開啟公開資料集
根據預設,Google Cloud 控制台會提供 BigQuery 公開資料集。
在以下範例中,您可以存取公開專案 bigquery-public-data
中的資料集。
前往 Google Cloud 控制台的「BigQuery」BigQuery頁面。
在「Explorer」窗格中,按一下「+ 新增資料」
。 在「Add data」對話方塊的「Filter By」窗格中,按一下
「Public datasets」。
你可以使用「搜尋市集」欄位或篩選器縮小搜尋範圍。
選取資料集,然後按一下「View dataset」(查看資料集)。
您可以在「Explorer」窗格中,查看所選資料集的詳細資料。
(非必要) 按一下資料集旁的
「View actions」(查看動作),即可查看更多選項。每個資料集都含有資料表,點選某個資料集旁的
「Toggle node」(展開或收合節點),就能查看當中的資料表。
查詢公開資料集
下列步驟中,您會查詢「usa_names」公開資料集,並找到 1910 年至 2013 年之間美國最常見的姓名:
前往 Google Cloud 控制台的「BigQuery」BigQuery頁面。
按一下
「SQL query」(SQL 查詢) 。將下列查詢複製到
查詢編輯器 :SELECT name, SUM(number) AS total FROM `bigquery-public-data.usa_names.usa_1910_2013` GROUP BY name ORDER BY total DESC LIMIT 10;
如果查詢有效,您就會看見勾號和查詢處理的資料量。如果查詢無效,則會顯示驚嘆號和錯誤訊息。
按一下
「Run」(執行) 。「Query results」(查詢結果) 部分會列出最常見的姓名。資料表的標題列會包含查詢中選取的每一個資料欄名稱。
(非必要) 如要顯示查詢的持續時間和處理的資料量,請按一下
「Query results」(查詢結果) 部分的「Job information」(工作資訊) 分頁標籤。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取您在本頁所用資源的費用,請按照下列步驟操作。
刪除專案
如果您使用 BigQuery 沙箱查詢公開資料集,則表示您的專案未啟用帳單功能。
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
如要刪除專案:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
後續步驟
- 瞭解 BigQuery 沙箱。
- 瞭解如何在Google Cloud 控制台中建立資料集及查詢資料表。
- 取得 BigQuery 的最新消息。
- 瞭解 BigQuery 定價。
- 瞭解 BigQuery 配額與限制。