SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  fcst_thresh,
'APCP_03' fcst_var,
  'FAR' stat_name,
  IF(ld.far=-9999,'NA',ld.far ) stat_value,
  IF(ld.far_ncl=-9999,'NA',ld.far_ncl  ) stat_ncl,
  IF(ld.far_ncu=-9999,'NA',ld.far_ncu  ) stat_ncu,
  IF(ld.far_bcl=-9999,'NA',ld.far_bcl) stat_bcl,
  IF(ld.far_bcu=-9999,'NA',ld.far_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cts ld
WHERE
    BINARY h.fcst_var IN ('APCP_03')
  AND   BINARY h.model IN ('HREFv2')
  AND   BINARY h.fcst_thresh IN ('>=0.25')
  AND   BINARY h.fcst_var = 'APCP_03'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.far != -9999
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  fcst_thresh,
'APCP_03' fcst_var,
  'PODY' stat_name,
  IF(ld.pody=-9999,'NA',ld.pody ) stat_value,
  IF(ld.pody_ncl=-9999,'NA',ld.pody_ncl  ) stat_ncl,
  IF(ld.pody_ncu=-9999,'NA',ld.pody_ncu  ) stat_ncu,
  IF(ld.pody_bcl=-9999,'NA',ld.pody_bcl) stat_bcl,
  IF(ld.pody_bcu=-9999,'NA',ld.pody_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cts ld
WHERE
    BINARY h.fcst_var IN ('APCP_03')
  AND   BINARY h.model IN ('HREFv2')
  AND   BINARY h.fcst_thresh IN ('>=0.25')
  AND   BINARY h.fcst_var = 'APCP_03'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.pody != -9999;

