Osio 3. Luku 3
single
Challenge: Product Inventory Analysis
Pyyhkäise näyttääksesi valikon
Tehtävä
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
productsandsales_transactionstables. - Use aggregate functions
SUM(for total units sold) andAVG(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, andaverage_inventory.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 3
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme