SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
'TMP' fcst_var,
  'ME' stat_name,
  IF(ld.me=-9999,'NA',ld.me ) stat_value,
  IF(ld.me_ncl=-9999,'NA',ld.me_ncl  ) stat_ncl,
  IF(ld.me_ncu=-9999,'NA',ld.me_ncu  ) stat_ncu,
  IF(ld.me_bcl=-9999,'NA',ld.me_bcl) stat_bcl,
  IF(ld.me_bcu=-9999,'NA',ld.me_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cnt ld
WHERE
    BINARY ld.fcst_init_beg IN ('2022-04-30 00:00:00', '2022-05-01 00:00:00', '2022-05-02 00:00:00', '2022-05-03 00:00:00', '2022-05-04 00:00:00', '2022-05-05 00:00:00', '2022-05-06 00:00:00', '2022-05-07 00:00:00', '2022-05-08 00:00:00', '2022-05-09 00:00:00', '2022-05-10 00:00:00', '2022-05-11 00:00:00', '2022-05-12 00:00:00')
  AND   BINARY h.model IN ('HREF_mem01', 'HREF_mem04')
  AND   BINARY ld.fcst_lead IN ('0', '10000', '20000', '30000', '40000', '50000', '60000', '70000', '80000', '90000', '100000', '110000', '120000', '130000', '140000', '150000')
  AND   BINARY h.fcst_var = 'TMP'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.me != -9999;

