Contoh SQL FIDDLE
1) Gunakan CTE untuk mendapatkan catatan nilai kode kapal maksimum berdasarkan ARDivisionNo, CustomerNountuk setiap Pelanggan
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) Untuk Menghapus catatan, gunakan Hapus kueri alih-alih Pilih dan ubah Where Clause menjadi rn> 1. Contoh 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;