Number Manufacturing Parts
Beginner Mode

Scenario

A manufacturing company needs to track its production timeline by combining manufacturing records with product details and numbering each entry chronologically.

Task

Write a Snowflake SQL query that:

  1. Joins {{ ref("production_records") }} with {{ ref("products") }} on product_id using an INNER JOIN
  2. Assigns a sequential row_number to each row ordered by manufacturing_date in ascending order using ROW_NUMBER()
  3. Returns the columns: product_id, manufacturing_date, manufacturing_location, product_name, product_type, and row_number

Schema

production_records

Column Type Description
product_id String Unique product identifier
manufacturing_date Date Date the product was manufactured
manufacturing_location String Factory or site where manufacturing took place

products

Column Type Description
product_id String Unique product identifier (matches production_records)
product_name String Name of the product
product_type String Category or type of the product

Example

production_records:

product_id manufacturing_date manufacturing_location
A1 2024-03-10 Austin
A2 2024-03-08 Portland
A3 2024-03-12 Austin
A4 2024-03-06 Chandler
A5 2024-03-15 Portland

products:

product_id product_name product_type
A1 Core_i7 Processor
A2 Arc_A770 GPU
A3 Xeon_W Processor
A4 Optane_900 Storage
A5 NUC_13 Mini_PC

Expected Output:

product_id manufacturing_date manufacturing_location product_name product_type row_number
A4 2024-03-06 Chandler Optane_900 Storage 1
A2 2024-03-08 Portland Arc_A770 GPU 2
A1 2024-03-10 Austin Core_i7 Processor 3
A3 2024-03-12 Austin Xeon_W Processor 4
A5 2024-03-15 Portland NUC_13 Mini_PC 5

Note: The row_number is a global sequential counter ordered by manufacturing_date. It does not reset per product or location. The earliest date gets row 1, the next date gets row 2, and so on.

Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →