'Best way to count the number of entries, grouped by a foreign key and which have dates within the last two years in SQL?

I am trying to write the SQL for a database project and basically I have a table called Organization which has an attribute called Project_id which is a foreign key of a table called Project. Project has an attribute called year. I want to find the Organizations which had more than 5 distinct projects assigned to them within any two year period but I am having trouble with it. I tried doing an inner join on Organization and Project but I am pretty much stuck there. If I group by year I won't be able to distinguish Organizations and if I group by Organization_id I can't distinguish between years.

Is this even possible in SQL?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source