SQL code for last date of appearence por each month listing all months

I have a list of deliveries of each month and i want to know for each month how many months has passed since the last delivery for each client.

for example seeing client 1

client month deliveries
1. 1 202101 2
1. 1 202102 0
1. 1 202103 1
1. 1 202104 0
1. 1 202105 0
1. 1 202106 1

the output of what i expect is the following table

client analisys_month months_since_last_delivery
1. 1 202101. 0
1. 1 202102. 1
1. 1 202103. 0
1. 1 202104. 1
1. 1 202105. 2
1. 1 202106. 0

my question is to make 1 query that can solve the variable months_since_last_delivery for each one f 36 months of performances whitout making union for 36 different querys one for each month

Written by