Upvotes and Downvotes for questions - restriction on score - networkwide

0

Please login or register to vote for this query.

(click on this box to dismiss)

History of Science and Math

Q&A for people interested in the history and origins of science and mathematics

declare @sql nvarchar(max)

create table #result (site sysname
                    , hostname sysname
                    , id integer
                    , title nvarchar(250)
                    , uid integer
                    , upvotes integer
                    , downvotes integer
                    , sco integer
                    , score integer)

select @sql = N'insert into #result' + STRING_AGG(concat(N'
select ''', name ,N''' as site
     , ''',hostname ,N'''
     ,   p.Id, p.Title,
  p.OwnerUserId,
  SUM(Case When v.VoteTypeId = 2 Then 1 Else NULL End) AS UpVotes,
  SUM(Case When v.VoteTypeId = 3 Then 1 Else NULL End) AS DownVotes,
  SUM(Case v.VoteTypeId When 2 Then 1 WHEN 3 Then -1 End) AS Difference,
  p.Score
from ', quotename(name), N'.dbo.votes v
inner join ', quotename(name), N'.dbo.posts p on
  v.PostId=p.Id 
where (p.PostTypeId=##type?1##) and
  (p.Score between ##minscore?0## and ##maxscore?0##)  
  and (p.CreationDate >= ''##Date1?2021-01-01##'') and (p.CreationDate <= ''##Date2?2022-01-01##'')
group by p.Id, p.Title, p.Score, p.OwnerUserId
'),N' 
union all')
from (select convert(nvarchar(max),name) name
    -- , convert(nvarchar(max),sitename)  sitename
    -- , meta
    -- , domain
     ,  concat( 
        -- based on an idea from Glorfindel 
        -- https://meta.stackexchange.com/a/321181
        (case sitename
        WHEN 'Audio' THEN 'video'
        WHEN 'Beer' THEN 'alcohol'
        WHEN 'CogSci' THEN 'psychology'
        WHEN 'Garage' THEN 'mechanics'
        WHEN 'Health' THEN 'medicalsciences'
        WHEN 'Moderators' THEN 'communitybuilding'
        WHEN 'Photography' THEN 'photo'
        WHEN 'Programmers' THEN 'softwareengineering'
        WHEN 'Vegetarian' THEN 'vegetarianism'
        WHEN 'Writers' THEN 'writing'
        WHEN 'Br' THEN 'pt'
        WHEN 'Mathoverflow' THEN concat((meta+'.'), sitename)
        ELSE case when sitename = domain then null else sitename end
        end +'.')
        , (case 
           when sitename <> 'mathoverflow' then (meta+'.') 
           else null 
           end) 
        , (case 
           when sitename <> 'mathoverflow' then concat((domain + '.'), 'com') 
           else 'net' 
           end)
        ) hostname
from (
select name
, case parsename(name,1) 
  when 'Meta' then parsename(name,2)
  else parsename(name,1) 
  end [sitename]
, case parsename(name,1) 
  when 'Meta' then 'meta'
  else null
  end [meta]
  , coalesce(parsename(name,3), parsename(name,2)) [domain]
from sys.databases
where database_id > 5
-- (name not like '%.Meta' or name = 'StackExchange.Meta')
) dbs
) dbsall

exec (@sql)



select top(##num?10000##)
  site, hostname, 
  id, title,  
  uid,     
  upvotes, downvotes, sco, score,
  concat('https://',hostname,'/q/',CAST(id AS varchar)),
  concat('https://',hostname,'/users/',CAST(uid AS varchar))
from #result
order by upvotes desc

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results