Demo for 11140169

0

Please login or register to vote for this query.

(click on this box to dismiss)

Internet of Things

Q&A for builders and users of networked sensors and control devices in the contexts of smart homes, industry automation, or environmental sensors

SELECT
* 
FROM
(SELECT 
    T.TagName,
    Year(a.creationDate) yr,
     CASE WHEN (GROUPING(Substring(DateName(m,a.creationDate),1,3)) = 1) THEN 'Total'
          ELSE Substring(DateName(m,a.creationDate),1,3)  
      END mh ,
    SUM(a.score) Score
FROM
  Posts a
  INNER JOIN Posts q
  ON a.ParentID = q.id
  INNER JOIN postTags pt 
  ON q.id = pt.PostId
  INNER JOIN Tags t
  ON Pt.TagiD = t.id
  WHERE a.owneruserID = ##UserID##
 
  
GROUP BY
    t.TagName,
    Year(a.creationDate) ,
    Substring(DateName(m,a.creationDate),1,3) 
    WITH ROLLUP
HAVING 
GROUPING (Year(a.creationDate))  = 0
    ) SourceTable
PIVOT
(
sum( Score )
FOR mh IN ([Jan],[Feb],[Mar],[Apr],[May],[Jun],[Jul],[Aug],[Sep],[Oct],[Nov],[Dec], [Total])
) AS PivotTable

Enter Parameters

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