Campione SQL FIDDLE
1) Utilizzare CTE per ottenere il record del valore massimo del codice della nave basato su ARDivisionNo, CustomerNoper ogni cliente
WITH cte AS (
SELECT*,
row_number() OVER(PARTITION BY ARDivisionNo, CustomerNo ORDER BY ShipToCode desc) AS [rn]
FROM t
)
Select * from cte WHERE [rn] = 1
2) Per eliminare il record utilizzare Elimina query invece di Selezionare e modificare Where Clause in rn> 1. Campione SQL FIDDLE
WITH cte AS (
SELECT*,
row_number() OVER(PARTITION BY ARDivisionNo, CustomerNo ORDER BY ShipToCode desc) AS [rn]
FROM t
)
Delete from cte WHERE [rn] > 1;
select * from t;