Использование оконной функции ROW_NUMBER()
с выражением CASE
в виде
SELECT Region, mCode, pCode
FROM
(
SELECT *,
ROW_NUMBER() OVER(PARTITION BY mCode ORDER BY CASE pCode WHEN 'D' THEN 0
WHEN 'L' THEN 1
WHEN 'E' THEN 2
WHEN 'O' THEN 3
END) RN
FROM
(
VALUES
('Europa' ,'AD', 'E'),
('Rest of the world' ,'AD', 'O'),
('East Europa' ,'AE', 'O'),
('Outside' ,'AE', 'L'),
('Rest of the world' ,'AE', 'E'),
('Asia' ,'AF', 'O'),
('North America' ,'AG', 'D'),
('Rest of the world' ,'AG', 'L'),
('North America' ,'AI', 'D'),
('Rest of the world' ,'AI', 'L'),
('America' ,'AI', 'L')
) T(Region, mCode, pCode)
) TT
WHERE RN = 1;
Live Demo