i have the following table
ID,CODE,ROW
8,56,26,
8,59,28,
8,98,29,
my goal is to create a partition where the max row is assigned the primary flag of 1 else set the others to 0
expected output
ID,CODE,ROW,primary
8,56,26,0
8,59,28,0
8,98,29,1
i have the following table
ID,CODE,ROW
8,56,26,
8,59,28,
8,98,29,
my goal is to create a partition where the max row is assigned the primary flag of 1 else set the others to 0
expected output
ID,CODE,ROW,primary
8,56,26,0
8,59,28,0
8,98,29,1
SELECT ID, CODE, ROW, CASE WHEN row_num = 1 THEN 1 ELSE 0 END AS [primary]
FROM (
    SELECT *, ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ROW DESC) AS row_num
    FROM dbo.table_name
) AS tn
            perfect thanks