SELECT
  model,
  fcst_thresh,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  vx_mask,
'APCP_03' fcst_var,
  'ACC' stat_name,
  IF(ld.acc=-9999,'NA',ld.acc ) stat_value,
  IF(ld.acc_ncl=-9999,'NA',ld.acc_ncl  ) stat_ncl,
  IF(ld.acc_ncu=-9999,'NA',ld.acc_ncu  ) stat_ncu,
  IF(ld.acc_bcl=-9999,'NA',ld.acc_bcl) stat_bcl,
  IF(ld.acc_bcu=-9999,'NA',ld.acc_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cts ld
WHERE
    BINARY h.vx_mask IN ('FULL')
  AND   BINARY ld.fcst_lead IN ('30000', '60000', '90000', '120000')
  AND   BINARY h.model IN ('QPF')
  AND   BINARY h.fcst_thresh IN ('>0.0', '>2.54', '>6.35')
  AND   BINARY ld.fcst_lead IN ('30000', '60000', '90000', '120000')
  AND   BINARY h.fcst_var = 'APCP_03'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.acc != -9999
UNION ALL
SELECT
  model,
  fcst_thresh,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  vx_mask,
'APCP_03' fcst_var,
  'CSI' stat_name,
  IF(ld.csi=-9999,'NA',ld.csi ) stat_value,
  IF(ld.csi_ncl=-9999,'NA',ld.csi_ncl  ) stat_ncl,
  IF(ld.csi_ncu=-9999,'NA',ld.csi_ncu  ) stat_ncu,
  IF(ld.csi_bcl=-9999,'NA',ld.csi_bcl) stat_bcl,
  IF(ld.csi_bcu=-9999,'NA',ld.csi_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cts ld
WHERE
    BINARY h.vx_mask IN ('FULL')
  AND   BINARY ld.fcst_lead IN ('30000', '60000', '90000', '120000')
  AND   BINARY h.model IN ('QPF')
  AND   BINARY h.fcst_thresh IN ('>0.0', '>2.54', '>6.35')
  AND   BINARY ld.fcst_lead IN ('30000', '60000', '90000', '120000')
  AND   BINARY h.fcst_var = 'APCP_03'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.csi != -9999;

