Usuários por mês

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow em Português

Perguntas e respostas para programadores profissionais e entusiastas

WITH mensal AS (
  SELECT 
    CONVERT(DATETIME, CONCAT(YEAR(CreationDate), '-', MONTH(CreationDate), '-01'), 20) AS Mes,
    COUNT(*) AS Novos
  FROM Users
  GROUP BY YEAR(CreationDate), MONTH(CreationDate)
)
SELECT 
  mensal.Mes,
  mensal.Novos,
  SUM(mensal.Novos) AS Acumulado
FROM mensal
  --INNER JOIN Users
  --ON CONCAT(YEAR(CreationDate), '-', MONTH(CreationDate)) <= Mensal.Mes
GROUP BY mensal.Mes, mensal.Novos



/*
SELECT 
CONVERT(DATETIME, CONCAT(YEAR(CreationDate), '-', MONTH(CreationDate), '-01'), 20) AS Mes,
COUNT(*) AS 'Usuários novos no mês',
(SELECT COUNT(*) FROM Users u WHERE YEAR(u.CreationDate) <= YEAR(Users.CreationDate) AND MONTH(u.CreationDate) <= MONTH(Users.CreationDate) ) AS 'Usuários totais'
FROM Users

GROUP BY YEAR(CreationDate), MONTH(CreationDate)
ORDER BY YEAR(CreationDate), MONTH(CreationDate)
*/

Enter Parameters

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