Tag demographics

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

-- Tag demographics

create table #BestTags
(
  TagId int,
  Uses int
)

insert into #BestTags
select top 20
 t.Id as TagId,
 count(pt.PostId) as Uses
from PostTags pt
inner join Tags t on t.Id = pt.TagId
group by t.Id, t.TagName
order by Uses desc

create table #UserPostInfo
(
  TagId int,
  PostCount int,
  UserId int,
  UserAge int
)

insert into #UserPostInfo
select
 bt.TagId,
 pt.PostId as Posts,
 u.Id as UserId,
 u.Age as UseAge
from #BestTags bt
inner join PostTags pt on pt.TagId = bt.TagId
inner join Posts p on p.Id = pt.PostId
inner join Users u on u.Id = p.OwnerUserId
where u.Age is not null

select
  upi.TagId,
  upi.UserId,
  avg(upi.UserAge) as UserAge
from #UserPostInfo upi
group by upi.UserId, upi.TagId

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results