R versus Python tags - quotient Py/R

0

Please login or register to vote for this query.

(click on this box to dismiss)

Quantitative Finance

Q&A for finance professionals and academics

select
  cast(cast(t.yr as varchar(4))+'-'+cast(t.mnth as varchar(2))+'-01' as date) as dt
  ,(case when t.r_mnth_count=0 then NULL else cast(t.py_mnth_count as float)/cast(t.r_mnth_count as float) end) as py_div_r
from
(
  select
    month(CreationDate) as mnth
    ,year(CreationDate) as yr
    -- count <r> tags
    ,sum(case when tags like '%<r>%' then 1 else 0 end) as r_mnth_count
    -- count <python> tags
    ,sum(case when tags like '%<python>%' then 1 else 0 end) as py_mnth_count
  from
    posts
  where
    -- tags are wrapped by <>
    tags like '%<r>%'
    or tags like '%<python>%'
  group by month(CreationDate), year(CreationDate)
) as t
-- exclude last (incomplete) month
where not (t.mnth=month(GETDATE()) and t.yr=year(GETDATE()))
and yr>=2011
order by t.yr asc, t.mnth asc

Enter Parameters

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