yearly_orders that selects product_id, the year of purchase_date, and the count of order_id for each product and year combination.HAVING clause to filter only those combinations where the count of order_id is greater than or equal to 3.product_id from the CTE.LEAD window function to get the next year for each product, partitioned by product_id and ordered by year.WHERE clause, check if the next year is exactly one year greater than the current year.DISTINCT to ensure each product_id is listed only once in the final result.
erDiagram
Orders {
int order_id PK
int product_id
int quantity
date purchase_date
}