Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Product Inventory Analysis | Advanced CTE Applications and Performance
Mastering Common Table Expressions (CTEs) in SQL
Section 3. Chapitre 3
single

single

bookChallenge: Product Inventory Analysis

Glissez pour afficher le menu

Tâche

Swipe to start coding

Create a query that uses a Common Table Expression (CTE) to analyze product inventory and sales. The query must calculate the total units sold and average inventory for each product, then select only those products whose total sales are above the overall average sales across all products.

Follow these steps to complete the task:

  • Use a Common Table Expression (CTE) to aggregate the total units sold and the average inventory for each product by joining the products and sales_transactions tables.
  • Use aggregate functions SUM (for total units sold) and AVG (for average inventory) within your CTE.
  • Create a second CTE or subquery to calculate the overall average of total units sold across all products.
  • Select and return only those products whose total units sold are greater than this overall average.
  • Ensure your final query filters products based on the computed average sales threshold and returns the required columns: product_id, product_name, total_sales, and average_inventory.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 3
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt