There exists a column in your data that represents the recipe -- let me just randomly guess that this is pmd_ppm_pr_code
. I assume the effective date is the most recent date. Let me assume that all products in the recipe have the same effective date.
If so, you want to use dense_rank()
, not row_number()
:
dense_rank() over (partition by pmd_ppm_pr_code order by pmd_ppm_date_effective desc) as seqnum
Your version returns the most recent date for each product separately. This returns the most recent by recipe.
Note that your order by
repeats the partitioning columns. This is totally unnecessary. The order by
is within a partition.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…