Skip to content

Instantly share code, notes, and snippets.

@azcoov
Created January 23, 2011 02:12
Show Gist options
  • Save azcoov/791736 to your computer and use it in GitHub Desktop.
Save azcoov/791736 to your computer and use it in GitHub Desktop.
SQL Tag Cloud
declare @MaxTagFrequency int
declare @tt_Tags table(
BlogCategory_ID int,
[Count] int
)
insert into
@tt_Tags
select top(@CountLimit)
bc.BlogCategory_ID,
count(bc.BlogCategory_ID)
from
BlogCategory bc
join BlogEntryCategory bec on bc.BlogCategory_ID = bec.BlogCategory_ID
group by
bc.BlogCategory_ID,
bc.Category
having count(bc.BlogCategory_ID) > 0
select @MaxTagFrequency = max([Count]) from @tt_Tags
select
tt.BlogCategory_ID,
bc.Category,
tt.[Count],
convert(decimal(6,2),(convert(float,tt.[Count]) / convert(float,@MaxTagFrequency)) * 100) as [Weight]
from
@tt_Tags tt
join BlogCategory bc on tt.BlogCategory_ID = bc.BlogCategory_ID
order by
bc.Category
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment