Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. alter procedure sp
  2. as
  3. begin
  4.  
  5. with CTE_RN as
  6. (
  7. select d.name as Distributor,r.name as Reseller,count(r.childdistributorid) over (partition by r.childdistributorid) as Rcount from distributor d
  8. join reseller r on r.childdistributorid=d.id group by
  9. d.name,r.name,r.childdistributorid
  10. )
  11. select * from CTE_RN group by Distributor,Reseller having Rcount=max(Rcount)
  12. end
  13. exec sp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement