I have a simple table with years and customer id and now I want to group by year and count distinct customers for each year. This is straightforward and works fine, my issue is that I don't want customers in year 1 to repeat in year 2, I only want to see new customers for each year. So how do I do that?
I have tried using count distinct with group by and even not in but it doesn't seem to work, it always gives me repeating values
select count (distinct customer ID), Year
FROM customers
group by year
lets say I have 100 customers for years 2015 to 2019 now I have
Year No of Customers
2015 30
2016 35
2017 40
2018 30
2019 10
Total 145 which is 45 more than 100 What I want is
Year No of Customers
2015 30
2016 30
2017 20
2018 20
2019 10
Total 100