0
0
GCPcloud~30 mins

BigQuery for analytics in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
BigQuery for analytics
📖 Scenario: You work as a data analyst for a retail company. The company collects sales data in Google BigQuery. You want to analyze the sales data to find total sales per product category.
🎯 Goal: Create a BigQuery SQL query that calculates total sales amount for each product category from the sales dataset.
📋 What You'll Learn
Create a table variable with sales data including product category and sales amount
Add a filter condition to select sales only from the year 2023
Write a SQL query to sum sales amount grouped by product category
Complete the query with ORDER BY clause to sort results by total sales descending
💡 Why This Matters
🌍 Real World
Retail companies analyze sales data to understand product performance and make business decisions.
💼 Career
Data analysts and cloud engineers use BigQuery to process large datasets efficiently for reporting and insights.
Progress0 / 4 steps
1
Create sales data table variable
Create a BigQuery table variable called sales_data with columns product_category (string), sales_amount (integer), and sale_year (integer). Insert these exact rows: ('Electronics', 1000, 2023), ('Clothing', 500, 2023), ('Electronics', 1500, 2022), ('Clothing', 700, 2023), ('Books', 300, 2023).
GCP
Need a hint?

Use CREATE TEMP TABLE to create the table and INSERT INTO to add rows.

2
Add filter for sales year 2023
Create a variable called filter_year and set it to 2023. This will be used to filter sales data for the year 2023.
GCP
Need a hint?

Use DECLARE to create a variable and set it to 2023.

3
Write SQL query to sum sales by category
Write a SQL query that selects product_category and the sum of sales_amount as total_sales from sales_data. Use WHERE sale_year = filter_year to filter data. Group the results by product_category.
GCP
Need a hint?

Use SUM() to add sales_amount and GROUP BY product_category.

4
Add ORDER BY clause to sort results
Add an ORDER BY total_sales DESC clause to the existing SQL query to sort the results by total sales in descending order.
GCP
Need a hint?

Use ORDER BY total_sales DESC to sort from highest to lowest sales.