SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
'BOWEN' fcst_var,
  'BCMSE' stat_name,
  IF(ld.bcmse=-9999,'NA',ld.bcmse ) stat_value,
  'NA' stat_ncl,
  'NA' stat_ncu,
  IF(ld.bcmse_bcl=-9999,'NA',ld.bcmse_bcl) stat_bcl,
  IF(ld.bcmse_bcu=-9999,'NA',ld.bcmse_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY h.model IN ('hr1.sub')
  AND   BINARY ld.fcst_lead IN ('0', '240000', '480000', '720000', '960000', '1200000', '1440000', '1680000', '1920000', '2160000', '2400000', '2640000', '2880000', '3120000', '3360000', '3600000', '3840000')
  AND   BINARY h.fcst_var = 'BOWEN'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.bcmse != -9999
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
'BOWEN' fcst_var,
  'BCRMSE' stat_name,
  IF(ld.bcmse=-9999,'NA',CAST(sqrt(ld.bcmse) as DECIMAL(30, 5))) stat_value,
  'NA' stat_ncl,
  'NA' stat_ncu,
  IF(ld.bcmse_bcl=-9999,'NA',CAST(sqrt(ld.bcmse_bcl) as DECIMAL(30, 5))) stat_bcl,
  IF(ld.bcmse_bcu=-9999,'NA',CAST(sqrt(ld.bcmse_bcu) as DECIMAL(30, 5))) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY h.model IN ('hr1.sub')
  AND   BINARY ld.fcst_lead IN ('0', '240000', '480000', '720000', '960000', '1200000', '1440000', '1680000', '1920000', '2160000', '2400000', '2640000', '2880000', '3120000', '3360000', '3600000', '3840000')
  AND   BINARY h.fcst_var = 'BOWEN'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.bcmse != -9999;

