sql server - UPDATE SQL Statement with group by (using a self join) to the same table -
i have sample data set
bookid book_name book_version_number new book version number (proposed) 1 xyz 1.0000 1.0000 1 xyz 1.0000 2.0000 2 abc 1.0000 1.0000 2 abc 1.0000 2.0000 2 abc 1.0000 3.0000
so, need incrementally , sequentially update new book version number grouped title..
i need put update sql..my update seems failing group clause not working
you use cte , row_number()
:
;with cte ( select bookid, bookname, book_version_number, row_number() over(partition bookid order (select null)) rn tablename ) update cte set book_version_number = rn
Comments
Post a Comment