jeudi 16 juin 2016

(SQL Server) Trying to figure out a calculation for consecutive fiscal years from today's date

I am new to SQL Server and this is my first question that I have ever posted to stackoverflow, hopefully, I am doing it, correctly.

Ok, lets say I have a table that has an ID, POSTEDDATE, and an AMOUNT field. I am trying to figure out using today's date and that our fiscal year is from July 1st to June 31st of every year. How would I create SQL that would give me ONLY the IDs that have given in consecutive FISCAL years, starting from TODAY'S DATE? And, it would ONLY give me records of people that have ONLY given CONSECUTIVELY (in other words, ONLY for 2 or more years?

So, for example, here is what I am referring to:

ID    POSTEDDATE    AMOUNT
1     6/15/2016     100.00
1     2/10/2015     5.00
2     6/15/2016     10.00
2     1/15/2016     50.00
3     1/10/2013     10.00
3     1/10/2012     60.00

Therefore, the ONLY record that I would get from this data set would be: ID ConsecYears 1 2

ID#2 gave 2 times in the SAME FISCAL YEAR and ID#3 gave in 2 consecutive years BUT it is not starting from TODAY'S DATE.

Does this make sense? If not, I can better clarify anything that is needed, please, just ask.

Thank you for any help, GrimReaper

Aucun commentaire:

Enregistrer un commentaire