WITH PocetPostovUzivatela AS ( SELECT u.Id, COUNT(p.Id) A...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Blender

Q&A for people who use Blender to create 3D graphics, animations, or games

WITH PocetPostovUzivatela AS (
    SELECT u.Id, COUNT(p.Id) AS PocetPostov
    FROM Users u
    LEFT JOIN Posts p ON u.Id = p.OwnerUserId
    GROUP BY u.Id
),
PercentoUzivatelov AS (
    SELECT 
        CASE 
            WHEN PocetPostov = 0 THEN '0'
            WHEN PocetPostov BETWEEN 1 AND 10 THEN '1-10'
            ELSE '>10'
        END AS Kategoria,
        COUNT(*) AS PocetUzivatelov
    FROM PocetPostovUzivatela
    GROUP BY 
        CASE 
            WHEN PocetPostov = 0 THEN '0'
            WHEN PocetPostov BETWEEN 1 AND 10 THEN '1-10'
            ELSE '>10'
        END
)
SELECT 
    Kategoria,
    ROUND((PocetUzivatelov * 100.0) / (SELECT COUNT(*) FROM Users), 2) AS Percento
FROM PercentoUzivatelov
ORDER BY 
    CASE 
        WHEN Kategoria = '0' THEN 1
        WHEN Kategoria = '1-10' THEN 2
        WHEN Kategoria = '>10' THEN 3
    END;

Enter Parameters

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