If the groups are fixed (users, managers) you can use something like this:
SELECT
u.id,
u.username,
count(case when um.group_id = 1 then 1 end) users,
count(case when um.group_id = 2 then 1 end) manager
FROM
user u INNER JOIN usergroups_map um
ON u.id = um.user_id
GROUP BY
u.id, u.username
otherwise you need do use a solution like this:
SET @sql = NULL;
SELECT GROUP_CONCAT(CONCAT('count(case when um.group_id=',id,' then 1 end) ', title))
FROM `group`
INTO @sql;
SET @sql = CONCAT('SELECT u.id, u.username, ', @sql, ' FROM
user u INNER JOIN usergroups_map um
ON u.id = um.user_id
GROUP BY
u.id, u.username');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Please see fiddle here.
If you need to create a view, just modify the above code with this:
SET @sql = NULL;
SELECT GROUP_CONCAT(CONCAT('count(case when um.group_id=',id,' then 1 end) ', title))
FROM `group`
INTO @sql;
SET @sql = CONCAT('CREATE VIEW yourview AS SELECT u.id, u.username, ', @sql, ' FROM
user u INNER JOIN usergroups_map um
ON u.id = um.user_id
GROUP BY
u.id, u.username');
DROP VIEW IF EXISTS yourview;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;