SELECT
  CAST("__mb_source"."date" AS date) AS "date",
  COUNT(*) AS "count"
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)
GROUP BY
  CAST("__mb_source"."date" AS date)
ORDER BY
  CAST("__mb_source"."date" AS date) ASC