Q&A for scientists using computers to solve scientific problems
declare @max_body_len int = ##MaxBodyLength:int?0## declare @max_excerpt_len int = ##MaxExcerptLength:int?1## declare @min_body_len int = ##MinBodyLength:int?-1## declare @min_excerpt_len int = ##MinExcerptLength:int?-1## declare @plot_min int = ##PlotMinimum:int?1## declare @bin int = ##Bin:Int?1## declare @bin_count int = ##BinCount:int?20## select t.Count, t.TagName, coalesce(len(pe.Body),0) as ExcerptLen, coalesce(len(pw.Body),0) as WikiLen, pe.CreationDate, ts.TargetTagName as SynonymTarget into #TagList from Tags t left join Posts pe on pe.Id = t.ExcerptPostId left join Posts pw on pw.Id = t.WikiPostId left join TagSynonyms ts on ts.SourceTagName = t.TagName where ((@max_body_len <= 0 and @max_excerpt_len <= 0 and @min_body_len = -1 and @min_excerpt_len = -1) or coalesce(len(pe.Body),0) < @max_excerpt_len or coalesce(len(pw.Body),0) < @max_body_len or len(pe.Body) > nullif(@min_excerpt_len,-1) or len(pw.Body) > nullif(@min_body_len,-1)) and ts.ApprovalDate is null select num into #Integers from (select @plot_min + (a.a + (10 * b.a) + (100 * c.a)) * @bin as num from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c ) a where a.num <= (select max(Count) from #TagList where Count < (@plot_min + @bin*@bin_count)) or a.num <= 3 -- min value of plot select Count, TagName, ExcerptLen, WikiLen, CreationDate, SynonymTarget -- ExcerptSuggestedEdit as [Suggested Edit Link], -- WikiSuggestedEdit as [Suggested Edit Link] from #TagList order by -- show tags that have a wiki but no excerpt first case when WikiLen > 0 and ExcerptLen = 0 then 0 else 1 end, Count desc, ExcerptLen asc, WikiLen asc, TagName select num as [Number of questions], count(Count) as [Number of tags with this many questions] from #TagList right join #Integers on Count between num and (num+@bin-1) group by num order by num select getdate() as 'Time of query'