SQL Famous Interview Question - Year on Year Growth | Lag|

Опубликовано: 22 Апрель 2026
на канале: GeekCoders
1,854
43

drop table tableA;
create TABLE tableA
(
Tenant varchar(20),
Year INT,
sales float
)

insert into tableA values
('tenant 1',2014,2000.00),
('tenant 1',2015,5000.00),
('tenant 2',2013,1000.00),
('tenant 2',2014,1500.00),
('tenant 2',2015,800.00)
select t.*, ((t.sales-t.last_year_sales)/t.last_year_sales)*100 as YoY from
(
select *,lag(sales,1) over (partition by tenant order by year) as last_year_sales from tableA
) t

Check out my course here: https://www.geekcoders.co.in/s/store

#sqlinterview #sqlinterviewquestionsandanswers #dataengineering