Skip to content

Instantly share code, notes, and snippets.

@RichVRed
Forked from azcoov/sqltagcloud.sql
Created September 13, 2017 19:40
Show Gist options
  • Save RichVRed/f7965a5e4292dd44bbdc86646a4e0c37 to your computer and use it in GitHub Desktop.
Save RichVRed/f7965a5e4292dd44bbdc86646a4e0c37 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