Q&A for people studying math at any level and professionals in related fields
SELECT tagname1, dup, total from ( SELECT TOP 5 Tags.TagName as tagname1, COUNT(distinct PostTags.PostId) AS dup FROM PostTags LEFT JOIN PostLinks on PostLinks.PostId = PostTags.PostId JOIN Tags on PostTags.TagId = Tags.Id WHERE LinkTypeId = 3 group by Tags.TagName ) dups LEFT JOIN ( SELECT TOP 5 Tags.TagName AS tagname, COUNT(distinct PostTags.PostId) AS total FROM PostTags LEFT JOIN PostLinks on PostLinks.PostId = PostTags.PostId JOIN Tags on PostTags.TagId = Tags.Id group by Tags.TagName )tots ON dups.tagname1 = tots.tagname order by total