Test

0

Please login or register to vote for this query.

(click on this box to dismiss)

Genealogy and Family History Meta

Q&A about the site for expert genealogists and people interested in genealogy or family history

with main AS (SELECT post_year,
       post_month,
       tag,
       month_count -- optional, not needed in main table
       
FROM (

  SELECT datepart(year,Posts.CreationDate) as post_year, 
         datepart(month,Posts.CreationDate) as post_month, 
         tags.TagName as tag, 
         COUNT(*) as month_count
         
  FROM PostTags as pt
    INNER JOIN Posts
    ON pt.PostId = Posts.Id
    INNER JOIN Tags as tags 
    ON pt.TagId = tags.Id
    
  WHERE tags.TagName in ('reactjs', 'react-native', 'swift',
                         'python', 'javascript', 'java')
  AND Posts.PostTypeId = 1
  
  GROUP BY datepart(year,Posts.CreationDate), 
           datepart(month,Posts.CreationDate), 
           tags.TagName
           
     ) AS subquery
     
     
GROUP BY post_year, 
         post_month, 
         tag,
         month_count), 

sub AS (SELECT datepart(year,Posts.CreationDate) as post_year, 
               datepart(month,Posts.CreationDate) as post_month,
               count(*) as total
        FROM Posts WHERE PostTypeId = 1
        GROUP BY datepart(year,Posts.CreationDate), 
                 datepart(month,Posts.CreationDate))
              

SELECT main.post_year,
       main.post_month,
       tag,
       month_count,
       total as total_questions_count,
       month_count * 100.0 / total as 'percent',
       SUM(month_count) OVER(PARTITION BY tag
                             ORDER BY tag
                             ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as total_count
FROM main INNER JOIN sub ON main.post_year = sub.post_year 
                         WHERE main.post_month = sub.post_month
ORDER BY post_year,
         post_month,
         tag;

Enter Parameters

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