WITH Table0 AS
(
   SELECT
      INTERVAL(LogEnergyEst, %106:bins)  AS  `.energy`,
      COUNT(IF(Weight>0, 1, NULL))     AS  `Signal`,
      COUNT(IF(Weight<0, 1, NULL))/5   AS  `Background`
      -- SUM(IF(Weight>0, 1./log10(Size), 0)) AS  `Signal`,
      -- SUM(IF(Weight<0, 1./log10(Size), 0)) AS  `Background`

      -- FIXME: Add excess vs theta
   FROM
      Excess
   GROUP BY
      `.energy`
   ORDER BY
      `.energy`
)

SELECT
   *,
   `Signal` - `Background`        AS `Excess`,
   LiMa(`Signal`, `Background`)   AS `Significance`,
   ExcErr(`Signal`, `Background`) AS `ErrExcess`
FROM
   Table0
