SELECT
   select_opened.period,
   select_opened.period_name,
   IFNULL(select_opened.opened_tickets, 0) as 'opened tickets',
   IFNULL(select_solved.solved_tickets, 0) as 'solved tickets',
   IFNULL(
      select_backlog.backlog_tickets,
      0
   ) as 'backlog'
FROM
   (
      SELECT
         DISTINCT DATE_FORMAT(glpi_tickets.date, '%y%m') AS period,
         DATE_FORMAT(
            MIN(glpi_tickets.date),
            '%b %Y'
         ) AS period_name,
         COUNT(DISTINCT glpi_tickets.id) AS opened_tickets
      FROM
         glpi_tickets
         LEFT JOIN glpi_tickets_users tu ON tu.tickets_id = glpi_tickets.id
         AND tu.type = 2
         LEFT JOIN glpi_groups_tickets gt ON gt.tickets_id = glpi_tickets.id
         AND gt.type = 2
         LEFT JOIN glpi_groups_tickets gtr ON gtr.tickets_id = glpi_tickets.id
         AND gtr.type = 1
         LEFT JOIN glpi_itilcategories ON glpi_itilcategories.id = glpi_tickets.itilcategories_id
         LEFT JOIN glpi_entities ON glpi_entities.id = glpi_tickets.entities_id
      WHERE
         glpi_tickets.is_deleted = '0'
      GROUP BY
         period
      ORDER BY
         period
   ) AS select_opened
   LEFT JOIN (
      SELECT
         DISTINCT DATE_FORMAT(glpi_tickets.solvedate, '%y%m') AS period,
         DATE_FORMAT(
            MIN(glpi_tickets.solvedate),
            '%b %Y'
         ) AS period_name,
         COUNT(DISTINCT glpi_tickets.id) AS solved_tickets
      FROM
         glpi_tickets
         LEFT JOIN glpi_tickets_users tu ON tu.tickets_id = glpi_tickets.id
         AND tu.type = 2
         LEFT JOIN glpi_groups_tickets gt ON gt.tickets_id = glpi_tickets.id
         AND gt.type = 2
         LEFT JOIN glpi_groups_tickets gtr ON gtr.tickets_id = glpi_tickets.id
         AND gtr.type = 1
         LEFT JOIN glpi_itilcategories ON glpi_itilcategories.id = glpi_tickets.itilcategories_id
         LEFT JOIN glpi_entities ON glpi_entities.id = glpi_tickets.entities_id
      WHERE
         glpi_tickets.is_deleted = '0'
      GROUP BY
         period
      ORDER BY
         period
   ) AS select_solved ON select_opened.period = select_solved.period
   LEFT JOIN (
      SELECT
         DISTINCT(
            DATE_FORMAT(list_date.period_l, '%y%m')
         ) AS period,
         DATE_FORMAT(
            MIN(list_date.period_l),
            '%b %Y'
         ) AS period_name,
         COUNT(
            DISTINCT(glpi_tickets.id)
         ) AS backlog_tickets
      FROM
         (
            SELECT
               DISTINCT period_l
            FROM
               (
                  SELECT
                     DISTINCT CONCAT(
                        LAST_DAY(
                           DATE_FORMAT(`date`, '%Y-%m-01 23:59:59')
                        ),
                        ' 23:59:59'
                     ) AS period_l
                  FROM
                     glpi_tickets
                  UNION
                  SELECT
                     DISTINCT CONCAT(
                        LAST_DAY(
                           DATE_FORMAT(
                              `solvedate`, '%Y-%m-01 23:59:59'
                           )
                        ),
                        ' 23:59:59'
                     ) AS period_l
                  FROM
                     glpi_tickets
               ) AS list_date_union
         ) AS list_date
         LEFT JOIN glpi_tickets ON glpi_tickets.date <= list_date.period_l
         AND (
            glpi_tickets.solvedate > list_date.period_l
            OR glpi_tickets.solvedate IS NULL
         )
         LEFT JOIN glpi_tickets_users tu ON tu.tickets_id = glpi_tickets.id
         AND tu.type = 2
         LEFT JOIN glpi_groups_tickets gt ON gt.tickets_id = glpi_tickets.id
         AND gt.type = 2
         LEFT JOIN glpi_groups_tickets gtr ON gtr.tickets_id = glpi_tickets.id
         AND gtr.type = 1
         LEFT JOIN glpi_itilcategories ON glpi_itilcategories.id = glpi_tickets.itilcategories_id
         LEFT JOIN glpi_entities ON glpi_entities.id = glpi_tickets.entities_id
      WHERE
         glpi_tickets.is_deleted = '0'
      GROUP BY
         period
   ) AS select_backlog ON select_opened.period = select_backlog.period
ORDER BY
   period;