Percentage of Posts w/ Scores of >1, 0 and <1, by Post Type

1

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
pt.Name AS 'Type',
COUNT(p.Id) AS 'Total',
CAST(
  ROUND(
    COUNT(CASE WHEN p.Score > 0 THEN 1 ELSE null END)
    / CAST(COUNT(p.Id) AS Float)
    * 100
  , 4) 
  AS nvarchar(7)
) + '%' AS '+',
CAST(
  ROUND(
    COUNT(CASE WHEN p.Score = 0 THEN 1 ELSE null END)
    / CAST(COUNT(p.Id) AS Float)
    * 100
  , 4) 
  AS nvarchar(7)
) + '%' AS '0',
CAST(
  ROUND(
    COUNT(CASE WHEN p.Score < 0 THEN 1 ELSE null END)
    / CAST(COUNT(p.Id) AS Float)
    * 100
  , 4) 
  AS nvarchar(7)
) + '%' AS '-'

FROM Posts p
JOIN PostTypes pt ON p.PostTypeId = pt.Id
GROUP BY pt.Name
ORDER BY COUNT(p.Id) DESC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results