答案 0 :(得分:1)
您可以将ROW_NUMBER()
与CASE EXPRESSION
:
SELECT t.code,t.name,t.year
FROM (SELECT s.*,ROW_NUMBER() OVER (PARTITION BY s.name
ORDER BY CASE WHEN s.year = 92 then 1
WHEN s.year = 93 then 2
ELSE 3
END) as rnk
FROM YourTable s) t
WHERE t.rnk = 1
我还考虑了多年后92,93
(优先考虑最后一次)的案例