Eksempel på SQL FIDDLE
1) Brug CTE til at få maks. forsendelseskodeværdipost baseret på ARDivisionNo, CustomerNofor hver kunde
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) For at slette posten, brug Slet forespørgsel i stedet for Vælg og skift Where-sætning til rn> 1. Sample 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;