From 88f50216d071113ffb72d3922b746344d9c5fc0e Mon Sep 17 00:00:00 2001 From: Krishna Dheeraj Krovi Date: Thu, 16 Jul 2026 00:03:49 -0700 Subject: [PATCH] added mock interview problem --- problem1.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 problem1.sql diff --git a/problem1.sql b/problem1.sql new file mode 100644 index 0000000..7d955ef --- /dev/null +++ b/problem1.sql @@ -0,0 +1,17 @@ +""" +1. We need to find all sales that occurred in the first year each product was sold +2. We first compute the first year that a product was sold. +3. Then we join it with the sales table on product id and year to fetch all the first year sales +""" + + +with cte1 as +( + select product_id, min(year) as year + from sales + group by product_id +) + +select c.product_id, c.year as first_year, quantity, price +from cte1 c +join sales s on c.product_id = s.product_id and c.year = s.year \ No newline at end of file