SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  fcst_thresh,
  vx_mask,
'apcp01' fcst_var,
  'CTC_FN_OY' stat_name,
  'NA' stat_value,
  ld.total,
  ld.fy_oy,
  ld.fy_on,
  ld.fn_oy,
  ld.fn_on,
  ld.ec_value 
FROM
  stat_header h,
  line_data_ctc ld
WHERE
    BINARY h.fcst_thresh IN ('>0')
  AND   BINARY h.vx_mask IN ('AIdom')
  AND   BINARY h.model IN ('AI_step12')
  AND HOUR(ld.fcst_valid_beg) IN ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23')
  AND   BINARY h.fcst_var = 'apcp01'
  AND ld.stat_header_id = h.stat_header_id
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  fcst_thresh,
  vx_mask,
'apcp01' fcst_var,
  'CTC_FY_OY' stat_name,
  'NA' stat_value,
  ld.total,
  ld.fy_oy,
  ld.fy_on,
  ld.fn_oy,
  ld.fn_on,
  ld.ec_value 
FROM
  stat_header h,
  line_data_ctc ld
WHERE
    BINARY h.fcst_thresh IN ('>0')
  AND   BINARY h.vx_mask IN ('AIdom')
  AND   BINARY h.model IN ('AI_step12')
  AND HOUR(ld.fcst_valid_beg) IN ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23')
  AND   BINARY h.fcst_var = 'apcp01'
  AND ld.stat_header_id = h.stat_header_id;

