SELECT
  "__mb_source"."type_alarme" AS "type_alarme",
  COUNT(*) AS "count"
FROM
  (
    SELECT
      CONCAT(
        "__mb_source"."source",
        ' ',
        "__mb_source"."alarm_code"
      ) AS "type_alarme"
    FROM
      (
        SELECT
          id,
          incident_number,
          itsm_recipient,
          ticket_status,
          incident_url,
          provider,
          title,
          description,
          "date",
          "source",
          status,
          criticality,
          urgency,
          priority,
          alarm_code,
          provider_details,
          tag,
          details,
          audit_login_creation,
          audit_date_creation,
          audit_login_modification,
          audit_date_modification,
          NULL AS comment
        FROM
          alerts
        UNION
        SELECT
          id,
          incident_number,
          itsm_recipient,
          ticket_status,
          incident_url,
          provider,
          title,
          description,
          "date",
          "source",
          status,
          criticality,
          urgency,
          priority,
          alarm_code,
          provider_details,
          tag,
          details,
          audit_login_creation,
          audit_date_creation,
          audit_login_modification,
          audit_date_modification,
          comment
        FROM
          archives
      ) AS "__mb_source"
    WHERE
      ("__mb_source"."status" <> 'UP')
      OR ("__mb_source"."status" IS NULL)
  ) AS "__mb_source"
GROUP BY
  "__mb_source"."type_alarme"
ORDER BY
  "count" DESC,
  "__mb_source"."type_alarme" ASC
LIMIT
  5