SQL Practice Logo

SQLPractice Online

Scenario SQL Question

Calculate Total Cost of Product with Sub-Components

Build mastery in Self Joins Hierarchical with this scenario-based SQL challenge and live execution support.

Problem Statement

Write a recursive CTE to calculate the total cost of product_id 1 (Bicycle) including all its sub-components. Return product_id, product_name, component_id, component_name, unit_cost, extended_cost (unit_cost * quantity), and level.

Relevant Tables

bill_of_materialscomponents

SQL Concepts Used in This Scenario

Strengthen your understanding with these targeted learning topics: