I would like to obtain, for each id_1, the number of common id_2s between the months of December and January. The example below:
id_1 | id_2 | Date |
---|---|---|
12 | 1 | 20221216 |
12 | 1 | 20230113 |
12 | 1 | 20230116 |
12 | 2 | 20221213 |
12 | 2 | 20230118 |
18 | 7 | 20221207 |
18 | 7 | 20220907 |
18 | 7 | 20230113 |
18 | 5 | 20230118 |
should return :
id_1 | Nb |
---|---|
12 | 2 |
18 | 1 |
I have looked for a short and optimal way to do this but I haven't found it. I would like to avoid doing several merges. Would you have ideas?