Grouping By Case Example

0

Please login or register to vote for this query.

(click on this box to dismiss)

Enter Query Description

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

-- Enter Query Title
-- Enter Query Description

SELECT 
   CASE 
            WHEN SCORE < 10 Then 'No Badge'
            WHEN SCORE BETWEEN 10 and 24 THEN 'Nice' 
            WHEN SCORE BETWEEN 24 and 99 THEN 'Good'
            WHEN SCORE >  99 THEN 'Great'
   End as BadgeType,
   Count(id) count
FROM
   Posts
WHERE
   PostTypeID in (1,2)
GROUP BY
    CASE 
            WHEN SCORE < 10 Then 'No Badge'
            WHEN SCORE BETWEEN 10 and 24 THEN 'Nice' 
            WHEN SCORE BETWEEN 24 and 99 THEN 'Good'
            WHEN SCORE >  99 THEN 'Great'
   End 

Enter Parameters

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