특정 연도의 등록 된 사용자 수를 월별로 그룹화하고자합니다. 다음은 내가 totalUsers를 들어, 이전 행의 결과를 추가하지 않는 올바른 결과를받지 못했습니다, 그러나 쿼리MySQL 사용자 정의 변수 COUNT와 함께 사용할 때 잘못된 결과를 반환합니다.
set @numberOfUsers := 0;
SELECT month(from_unixtime(u.createdDate)) as month, count(u.id) as monthlyusers,
(@numberOfUsers := @numberOfUsers + count(u.id)) as totalUsers
FROM user u
where year(from_unixtime(u.createdDate)) = '2016'
group by month(from_unixtime(u.createdDate));
입니다.
month | monthlyUsers | totalUsers
10 | 1 | 1
11 | 3 | 3
11 번째 월의 총 사용자 수는 4 여야합니다. 쿼리에서 잘못된 부분을 확인하십시오. 도움이 되었습니까?