SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  vx_mask,
'U10' fcst_var,
  'FBAR' stat_name,
  IF(ld.fbar=-9999,'NA',ld.fbar ) stat_value,
  IF(ld.fbar_ncl=-9999,'NA',ld.fbar_ncl  ) stat_ncl,
  IF(ld.fbar_ncu=-9999,'NA',ld.fbar_ncu  ) stat_ncu,
  IF(ld.fbar_bcl=-9999,'NA',ld.fbar_bcl) stat_bcl,
  IF(ld.fbar_bcu=-9999,'NA',ld.fbar_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY h.vx_mask IN ('coast')
  AND   BINARY h.model IN ('AI_step03')
  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 = 'U10'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.fbar != -9999
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  vx_mask,
'U10' fcst_var,
  'OBAR' stat_name,
  IF(ld.obar=-9999,'NA',ld.obar ) stat_value,
  IF(ld.obar_ncl=-9999,'NA',ld.obar_ncl  ) stat_ncl,
  IF(ld.obar_ncu=-9999,'NA',ld.obar_ncu  ) stat_ncu,
  IF(ld.obar_bcl=-9999,'NA',ld.obar_bcl) stat_bcl,
  IF(ld.obar_bcu=-9999,'NA',ld.obar_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY h.vx_mask IN ('coast')
  AND   BINARY h.model IN ('AI_step03')
  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 = 'U10'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.obar != -9999
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  vx_mask,
'V10' fcst_var,
  'FBAR' stat_name,
  IF(ld.fbar=-9999,'NA',ld.fbar ) stat_value,
  IF(ld.fbar_ncl=-9999,'NA',ld.fbar_ncl  ) stat_ncl,
  IF(ld.fbar_ncu=-9999,'NA',ld.fbar_ncu  ) stat_ncu,
  IF(ld.fbar_bcl=-9999,'NA',ld.fbar_bcl) stat_bcl,
  IF(ld.fbar_bcu=-9999,'NA',ld.fbar_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY h.vx_mask IN ('coast')
  AND   BINARY h.model IN ('AI_step03')
  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 = 'V10'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.fbar != -9999
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  vx_mask,
'V10' fcst_var,
  'OBAR' stat_name,
  IF(ld.obar=-9999,'NA',ld.obar ) stat_value,
  IF(ld.obar_ncl=-9999,'NA',ld.obar_ncl  ) stat_ncl,
  IF(ld.obar_ncu=-9999,'NA',ld.obar_ncu  ) stat_ncu,
  IF(ld.obar_bcl=-9999,'NA',ld.obar_bcl) stat_bcl,
  IF(ld.obar_bcu=-9999,'NA',ld.obar_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY h.vx_mask IN ('coast')
  AND   BINARY h.model IN ('AI_step03')
  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 = 'V10'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.obar != -9999;

