SELECT custid, SUM(amount) FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY custid, transid ORDER BY transid) AS seqnum FROM table_1 t ) t WHERE seqnum = 1;