localStorage.setItem('game', "League of Legends");
let game = localStorage.getItem('game');
localStorage.setItem('games', JSON.stringify(["League of Legends", "Doom", "Duke Nukem 3D"]));
let games = JSON.parse(localStorage.getItem('game'));
console.log(games);
select t.department_id,
t1.item as type_1,
t2.item as type_2,
...
from t
left join (select t.department_id, t.item from t where t.type_id = 1) t1 on t1.department_id = t.department_id
left join (select t.department_id, t.item from t where t.type_id = 2) t2 on t2.department_id = t.department_id
...
where (SUBSTRING_INDEX(t.item, '_', -1) + 0 = SUBSTRING_INDEX(t1.item, '_', -1) + 0 or t1.item is null)
and (SUBSTRING_INDEX(t.item, '_', -1) + 0 = SUBSTRING_INDEX(t2.item, '_', -1) + 0 or t2.item is null)
...
-- тут нужно получить равенство всех субиндексов 0000i от t.item сравнить со всеми tn.item
order by t.department_id, SUBSTRING_INDEX(t.item, '_', -1) + 0