SELECT PromoFileVersion, FYearWeek, WeekPriority, PromoEventId
FROM PromoCalendar p
where PromoFileVersion = (select max(PromoFileVersion) PromoFileVersion
from PromoCalendar p1
where p1.FYearWeek = p.FYearWeek
and p1.WeekPriority = p.WeekPriority
GROUP BY FYearWeek, WeekPriority);
You can use row_number()
:
select pc.*
from (select pc.*,
row_number() over (partition by FYearWeek, WeekPriority order by PromoFileVersion desc) as seq
from PromoCalendar pc
) pc
where pc.seq = 1;
If you have ties with PromoFileVersion
then you cas use dense_rank()
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.