sql query distinct with Row_Number

后端 未结 8 1102
死守一世寂寞
死守一世寂寞 2020-11-28 09:00

I am fighting with the distinct keyword in sql. I just want to display all row numbers of unique (distinct) values in a column & so I tried:

8条回答
  •  情歌与酒
    2020-11-28 09:47

    Try this:

    ;WITH CTE AS (
                   SELECT DISTINCT id FROM table WHERE fid = 64
                 )
    SELECT id, ROW_NUMBER() OVER (ORDER BY  id) AS RowNum
      FROM cte
     WHERE fid = 64
    

提交回复
热议问题