SELECT
  DATE_FORMAT(:starttime, '%Y-%m-%d %H:%i') AS StartTimestamp,
  DATE_FORMAT(:endtime,   '%Y-%m-%d %H:%i') AS EndTimestamp,
  COALESCE(c.Fluid_Inbound_Merge_1,0) + COALESCE(c.Fluid_Inbound_Merge_2,0) + 
  COALESCE(c.Fluid_Inbound_Merge_3,0) + COALESCE(c.Fluid_Inbound_Merge_4,0) + 
  COALESCE(c.Fluid_Inbound_Merge_5,0) + COALESCE(c.Fluid_Inbound_Merge_6,0) + 
  COALESCE(c.Fluid_Inbound_Merge_7,0) + COALESCE(c.Non_Con_Merge,0) + 
  COALESCE(c.NCP,0) + COALESCE(c.Bulk_Inbound_MCM04,0) + 
  COALESCE(c.Fluid_Outbound_MCM04,0) + COALESCE(c.Problem_Solve_MCM04,0) + 
  COALESCE(c.Bulk_Inbound_MCM05,0) + COALESCE(c.Fluid_Outbound_MCM05,0) + 
  COALESCE(c.Problem_Solve_MCM05,0) + COALESCE(c.NCS1,0) + COALESCE(c.NCS2,0) + 
  COALESCE(c.BYB,0) + COALESCE(c.BYA,0) + COALESCE(c.BYC,0) + COALESCE(c.BYD,0) + 
  COALESCE(c.Chutes_MCM04,0) + COALESCE(c.Chutes_MCM05,0) AS Total,
  COALESCE(c.Fluid_Inbound_Merge_1,0) AS Fluid_Inbound_Merge_1,
  COALESCE(c.Fluid_Inbound_Merge_2,0) AS Fluid_Inbound_Merge_2,
  COALESCE(c.Fluid_Inbound_Merge_3,0) AS Fluid_Inbound_Merge_3,
  COALESCE(c.Fluid_Inbound_Merge_4,0) AS Fluid_Inbound_Merge_4,
  COALESCE(c.Fluid_Inbound_Merge_5,0) AS Fluid_Inbound_Merge_5,
  COALESCE(c.Fluid_Inbound_Merge_6,0) AS Fluid_Inbound_Merge_6,
  COALESCE(c.Fluid_Inbound_Merge_7,0) AS Fluid_Inbound_Merge_7,
  COALESCE(c.Non_Con_Merge,0) AS Non_Con_Merge,
  COALESCE(c.NCP,0) AS NCP,
  COALESCE(c.Bulk_Inbound_MCM04,0) AS Bulk_Inbound_MCM04,
  COALESCE(c.Fluid_Outbound_MCM04,0) AS Fluid_Outbound_MCM04,
  COALESCE(c.Problem_Solve_MCM04,0) AS Problem_Solve_MCM04,
  COALESCE(c.Bulk_Inbound_MCM05,0) AS Bulk_Inbound_MCM05,
  COALESCE(c.Fluid_Outbound_MCM05,0) AS Fluid_Outbound_MCM05,
  COALESCE(c.Problem_Solve_MCM05,0) AS Problem_Solve_MCM05,
  COALESCE(c.NCS1,0) AS NCS1,
  COALESCE(c.NCS2,0) AS NCS2,
  COALESCE(c.BYB,0) AS BYB,
  COALESCE(c.BYA,0) AS BYA,
  COALESCE(c.BYC,0) AS BYC,
  COALESCE(c.BYD,0) AS BYD,
  COALESCE(c.Chutes_MCM04,0) AS Chutes_MCM04,
  COALESCE(c.Chutes_MCM05,0) AS Chutes_MCM05
FROM (SELECT 1) AS p
LEFT JOIN (
  SELECT
    SUM(Fluid_Inbound_Merge_1 = 1) AS Fluid_Inbound_Merge_1,
    SUM(Fluid_Inbound_Merge_2 = 1) AS Fluid_Inbound_Merge_2,
    SUM(Fluid_Inbound_Merge_3 = 1) AS Fluid_Inbound_Merge_3,
    SUM(Fluid_Inbound_Merge_4 = 1) AS Fluid_Inbound_Merge_4,
    SUM(Fluid_Inbound_Merge_5 = 1) AS Fluid_Inbound_Merge_5,
    SUM(Fluid_Inbound_Merge_6 = 1) AS Fluid_Inbound_Merge_6,
    SUM(Fluid_Inbound_Merge_7 = 1) AS Fluid_Inbound_Merge_7,
    SUM(Non_Con_Merge = 1) AS Non_Con_Merge,
    SUM(NCP = 1) AS NCP,
    SUM(Bulk_Inbound_MCM04 = 1) AS Bulk_Inbound_MCM04,
    SUM(Fluid_Outbound_MCM04 = 1) AS Fluid_Outbound_MCM04,
    SUM(Problem_Solve_MCM04 = 1) AS Problem_Solve_MCM04,
    SUM(Bulk_Inbound_MCM05 = 1) AS Bulk_Inbound_MCM05,
    SUM(Fluid_Outbound_MCM05 = 1) AS Fluid_Outbound_MCM05,
    SUM(Problem_Solve_MCM05 = 1) AS Problem_Solve_MCM05,
    SUM(NCS1 = 1) AS NCS1,
    SUM(NCS2 = 1) AS NCS2,
    SUM(BYB = 1) AS BYB,
    SUM(BYA = 1) AS BYA,
    SUM(BYC = 1) AS BYC,
    SUM(BYD = 1) AS BYD,
    SUM(Chutes_MCM04 = 1) AS Chutes_MCM04,
    SUM(Chutes_MCM05 = 1) AS Chutes_MCM05
  FROM jam_area
  WHERE t_stamp BETWEEN :starttime AND :endtime
) AS c ON 1=1;