SELECT ticket_number, some_id
FROM (
SELECT ticket_number, some_id,
rank() OVER (PARTITION BY ticket_number ORDER BY some_id DESC) RnkDESK,
rank() OVER (PARTITION BY ticket_number ORDER BY some_id ASC) RnkASC
FROM table ) x
WHERE X.RnkDESK = 1 OR X.RnkASC = 1