Skip to content

Instantly share code, notes, and snippets.

@qcom
Created March 16, 2015 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qcom/7ec51c3f89a051469d93 to your computer and use it in GitHub Desktop.
Save qcom/7ec51c3f89a051469d93 to your computer and use it in GitHub Desktop.
why
select * from (
select C3.ObjectId, C3.CategoryId, C3.CategorizationId, TheCount,
ROW_NUMBER() OVER (ORDER BY C3.ObjectId, C3.CategoryId, C3.Categorizationid desc) as RowNumber
from Categorization as C3 right outer join (
select (select Code from Product where ProductId = ObjectId) as Code, C1.ObjectId, C1.CategoryId, (
select count(*) from Categorization as C2 where C2.ObjectId = C1.ObjectId and C2.CategoryId = C1.CategoryId
) as TheCount
from Categorization as C1
where (select count(*) from Categorization as C2 where C2.ObjectId = C1.ObjectId and C2.CategoryId = C1.CategoryId) > 1
group by C1.CategoryId, C1.ObjectId
) as R1 ON C3.ObjectId = R1.ObjectId and C3.CategoryId = R1.CategoryId
where C3.ObjectId = 599
) seq where seq.RowNumber between 2 and TheCount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment