I have a table A with date column and Im trying to join with table B. My expected output is, I only need 1 year old records from table B
Table A
ID name qty price date
1 abc 20 3 17/01/2021
2 abc 10 5 18/03/2022
3 def 10 7 24/01/2017
4 def 40 2 25/05/2015
Expected Output
ID name qty price date
1 abc 20 3 17/01/2021
1 abc 29 28 16/01/2021
1 abc 19 18 15/01/2021
1 . . . till 17/01/2020
I tried below query, but it fetches all historical record.
select * from
table a inner join
table b
on a.ID = b.ID
and year(a.date) > DATEADD(year, -1, b.date)