Menu
Coddy logo textTech

Recap - LEAD & LAG

Part of the Fundamentals section of Coddy's SQL journey — lesson 62 of 72.

challenge icon

Challenge

Medium

Available tables and columns:

  • <b>air_conditioners</b>: <b>id</b>, <b>efficiency</b>, <b>strength</b>, <b>month</b>

We want to track how air conditioner performance changes over time. Your task is to find air conditioners that had declining performance between months.

Here's what to do:

  1. For each air conditioner in each month, calculate its performance ratio by dividing the average efficiency by the average strength using AVG(efficiency)/AVG(strength), grouped by id and month
  2. Compare each air conditioner's current month performance with its performance two months later
  3. Find cases where the current performance is significantly better than future performance (current ratio ÷ future ratio > 0.5)
  4. Return the air conditioner id, month, and the comparison ratio for these cases

Try it yourself

All lessons in Fundamentals