必须删除多个括号
将所有括号与左边保持相同距离有助于获得干净的代码
select * from
(
select year,
subs,
unsubs,
LAG(subs,1) OVER(ORDER BY year) as sub_py,
LAG(unsubs,1) OVER(ORDER BY year) as unsub_py
FROM
(
SELECT
DATE_FORMAT(subscription_started,"%Y") as year,
SUM(Case WHEN subscription_started is not null then 1 else 0 end) as subs
FROM user_churn
group by year
) as s
INNER JOIN
(
SELECT
DATE_FORMAT(subscription_ended,"%Y") as year_unsub,
SUM(Case WHEN subscription_ended is not null then 1 else 0 end) as unsubs
FROM user_churn
group by year_unsub
) as us
on s.year=us.year_unsub
) as drv