Professional Documents
Culture Documents
Introduction
In this codelab, you will use the BigQuery web UI to query public
datasets, load your own data, and export data to a Cloud Storage
bucket.
2. Getting set up
Create a project
Note: If you have one or more existing projects, click the project
name to the right of Google Cloud Platform in the title bar and
choose Create a project.
Click Compose Query. In the New Query text area, copy and
paste the following SQL query. The query uses
the #standardSQL prefix to specify that BigQuery should treat this
query as standard SQL. The UI validates the query and displays a
green checkmark below the text area to indicate that the syntax is
valid.
#standardSQL
SELECT badge_name AS First_Gold_Badge,
COUNT(1) AS Num_Users,
ROUND(AVG(tenure_in_days)) AS Avg_Num_Days
FROM
(
SELECT
badges.user_id AS user_id,
badges.name AS badge_name,
TIMESTAMP_DIFF(badges.date, users.creation_date, DAY) AS
tenure_in_days,
ROW_NUMBER() OVER (PARTITION BY badges.user_id
ORDER BY badges.date) AS row_number
FROM
`bigquery-public-data.stackoverflow.badges` badges
JOIN
`bigquery-public-data.stackoverflow.users` users
ON badges.user_id = users.id
WHERE badges.class = 1
)
WHERE row_number = 1
GROUP BY First_Gold_Badge
ORDER BY Num_Users DESC
LIMIT 10
Click Run Query. The query generates the top 10 gold badges,
ranked by how many users got them as their first gold badges.
The query also determines how many days it took for these gold
badges to be obtained on average.
You can also query sets of tables using wildcard table names. For
more information, see Querying sets of tables using wildcard
tables.
In the Source Data section, click the Choose file button. Navigate
to the data you unzipped earlier, and select the yob2014.txt file.
Replace the contents of the Schema input area with the following
schema:
name:string,gender:string,count:integer
Click OK.
4. Cleaning up
Select the bucket that contains your BigQuery export data, and
click Delete.
In the Shut down project dialog, read the notes and then, type
the project ID.