How to select only first ROW_NUMBER combined with SUM
How to select only first ROW_NUMBER combined with SUM I like to group my table by [ID] while using SUM and also bring back [Product_Name] of the top ROW_NUMBER - not sure if I should use ROW_NUMBER , GROUPING SETS or loop through everything with FETCH... this is what I tried: ROW_NUMBER ROW_NUMBER GROUPING SETS DECLARE @SampleTable TABLE ( [ID] INT, [Price] MONEY, [Product_Name] VARCHAR(50) ) INSERT INTO @SampleTable VALUES (1, 100, 'Product_1'), (1, 200, 'Product_2'), (1, 300, 'Product_3'), (2, 500, 'Product_4'), (2, 200, 'Product_5'), (2, 300, 'Product_6'); SELECT [ID], [Product_Name], [Price], SUM([Price]) OVER (PARTITION BY [ID]) AS [Price_Total], ROW_NUMBER() OVER (PARTITION BY [ID] ORDER BY [ID]) AS [Row_Number] FROM @SampleTable T1 My desired results - only two records: 1 ...