Wednesday, September 23, 2015

SQL Server Query for Rank (RowNumber) and Groupings


In SQL Server select statement, to generate and restart Group wise Serial No. following SQL Statement can be used.

in the following statement

select 
        ProductCategory, 
row_number() over(partition by ProductCategory order by ProductCategory) AS SrNo,
        ItemName
from items
group by ProductCategory
order by ProductCategory


No comments: