SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  if( (select fcst_lead_offset FROM model_fcst_lead_offset WHERE model = h.model) is NULL , ld.fcst_lead , ld.fcst_lead + (select fcst_lead_offset FROM model_fcst_lead_offset WHERE model = h.model) ) fcst_lead,
  fcst_lev,
  obtype,
  vx_mask,
'PM25' 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 h.fcst_lev IN ('Z8')
  AND   BINARY h.obtype IN ('AIRNOW_HOURLY_AQOBS')
  AND   BINARY h.vx_mask IN ('CONUS')
  AND   BINARY ld.fcst_init_beg IN ('2024-01-10 00:00:00', '2024-01-11 00:00:00', '2024-01-12 00:00:00', '2024-01-13 00:00:00', '2024-01-14 00:00:00', '2024-01-15 00:00:00', '2024-01-16 00:00:00', '2024-01-17 00:00:00', '2024-01-18 00:00:00', '2024-01-19 00:00:00', '2024-01-20 00:00:00', '2024-01-21 00:00:00', '2024-01-22 00:00:00', '2024-01-23 00:00:00', '2024-01-24 00:00:00', '2024-01-25 00:00:00', '2024-01-26 00:00:00', '2024-01-27 00:00:00', '2024-01-28 00:00:00', '2024-01-29 00:00:00', '2024-01-30 00:00:00', '2024-01-31 00:00:00', '2024-02-01 00:00:00', '2024-02-02 00:00:00', '2024-02-03 00:00:00', '2024-02-04 00:00:00', '2024-02-05 00:00:00', '2024-02-06 00:00:00', '2024-02-07 00:00:00', '2024-02-08 00:00:00')
  AND   BINARY h.model IN ('RRFS_verification_mem000')
  AND   BINARY  if( (select fcst_lead_offset FROM model_fcst_lead_offset WHERE model = h.model) is NULL , ld.fcst_lead , ld.fcst_lead + (select fcst_lead_offset FROM model_fcst_lead_offset WHERE model = h.model) )  IN ('0', '10000', '20000', '30000', '40000', '50000', '60000', '70000', '80000', '90000', '100000', '110000', '120000', '130000', '140000', '150000', '160000', '170000', '180000', '190000', '200000', '210000', '220000', '230000', '240000', '250000', '260000', '270000', '280000', '290000', '300000', '310000', '320000', '330000', '340000', '350000', '360000', '370000', '380000', '390000', '400000', '410000', '420000', '430000', '440000', '450000', '460000', '470000', '480000', '490000', '500000', '510000', '520000', '530000', '540000', '550000', '560000', '570000', '580000', '590000', '600000', '610000', '620000', '630000', '640000', '650000', '660000', '670000', '680000', '690000', '700000', '710000', '720000', '730000', '740000', '750000', '760000', '770000', '780000', '790000', '800000', '810000', '820000', '830000', '840000')
  AND   BINARY h.fcst_var = 'PM25'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.me != -9999;

