Skip to main content

Posts

Showing posts from June, 2018

Partition in SQL

I have been off track for a while due to heavy office commitments, even if it had me away I was able to gain a good chunk of knowledge which I’m willing to share with you all. Today I’m gonna discuss the impressive partition function which saved my day in so many ways. It is as simple as its name states, we are partitioning the query output by giving a set of condition. This can be useful for many needs like given below. 1.         Identify and remove the duplicates precisely. 2.        Unlike the conventional Group By syntax, this allows more customized grouping when retrieving data. Since I work with school data all night long I came up with a code from what I do. WITH HighestMark AS (   SELECT        [StudentID]       , [Year]       , [Semester]       , [FullName]       , [Grade]       , [Year]       , [Semester]       , [Subject]       , [Mark]       , row_number () OVER ( PARTITION BY [StudentID] , [Subject] ORDER BY [StudentID