Monday, December 30, 2019

TOP 5 ITEMS FROM EACH CATEGORY

;with Rohi  as
(
 select
GlobalCodeName ,sortorder,GlobalCodeCategoryID,
 ROW_NUMBER() OVER (PARTITION BY GlobalCodeCategoryID order by GlobalCodeCategoryID  ) AS  'RowNum'

  from GlobalCodes
  )
  select * from Rohi where RowNum <=5
 
  select (max(SortOrder)) + 1 from GlobalCodes where GlobalCodeCategoryID=13
  --pass the date
  select Isnull(max(SortOrder),0) + 1 from GlobalCodes where GlobalCodeCategoryID=13

No comments: