Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Product Category Tree Expansion | Recursive CTEs and Hierarchical Data
/
Mastering Common Table Expressions (CTEs) in SQL
Sección 2. Capítulo 3
single

single

bookChallenge: Product Category Tree Expansion

Desliza para mostrar el menú

Tarea

Swipe to start coding

Create a recursive CTE to list all subcategories under the "Electronics" category in the product_categories table, displaying each category's depth in the hierarchy.

  • Use a recursive CTE to traverse the product category hierarchy starting from the "Electronics" category.
  • For each category, include its category_id, category_name, parent_category_id, and the hierarchy depth.
  • The root category ("Electronics") should have a depth of 1.
  • Each direct child should have a depth of 2, their children a depth of 3, and so on.
  • Only include categories that are descendants of "Electronics" (including "Electronics" itself).

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 3
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt