Avg score by month for tag

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

select 
    -- p.id as [Post Link]
    -- , p.Score
    -- , t.tagname
    -- , tv.value
    -- , p.CreationDate
       SUM(p.Score) AS Score,
       COUNT(*) AS Answers,
       ROUND(1.0 * SUM(p.Score)/COUNT(*), 2) AS ScorePerAnswer,
       CAST(
            CAST(DATEPART(YEAR, p.CreationDate) AS NVARCHAR) + '-' + 
            CAST(DATEPART(MONTH, p.CreationDate) AS NVARCHAR) + '-01'
            AS DATETIME) AS 'Month'
from posts p
  inner join posts q 
    on q.id = coalesce(p.parentid, p.id) -- only questions have tags
  
  inner join posttags pt 
    on pt.postid = q.id
  
  inner join tags t 
    on t.id = pt.tagid
  
  cross join string_split(##tags:string?powerbi,dax##, ',') tv

where 
  t.tagname = tv.value
  and p.owneruserid = ##userid?1903793##
  and p.posttypeid in (2)
 group by
   DATEPART(YEAR, p.CreationDate), 
   DATEPART(MONTH, p.CreationDate)
--order by p.CreationDate desc

Enter Parameters

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