SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  obtype,
  fcst_lev,
  vx_mask,
'AOTK' fcst_var,
  'FBAR' stat_name,
  'NA' stat_value,
  ld.total,
  ld.fbar,
  ld.obar,
  ld.fobar,
  ld.ffbar,
  ld.oobar,
 ld.mae
FROM
  stat_header h,
  line_data_sl1l2 ld
WHERE
    BINARY h.obtype IN ('AERONET_AOD')
  AND   BINARY h.fcst_lev IN ('L0')
  AND   BINARY ld.fcst_init_beg IN ('2023-07-02 00:00:00', '2023-07-03 00:00:00', '2023-07-04 00:00:00', '2023-07-05 00:00:00', '2023-07-06 00:00:00', '2023-07-07 00:00:00', '2023-07-08 00:00:00', '2023-07-09 00:00:00', '2023-07-10 00:00:00', '2023-07-11 00:00:00', '2023-07-12 00:00:00', '2023-07-13 00:00:00', '2023-07-14 00:00:00', '2023-07-15 00:00:00', '2023-07-16 00:00:00', '2023-07-17 00:00:00', '2023-07-18 00:00:00', '2023-07-19 00:00:00', '2023-07-20 00:00:00', '2023-07-21 00:00:00', '2023-07-22 00:00:00', '2023-07-23 00:00:00', '2023-07-24 00:00:00', '2023-07-25 00:00:00', '2023-07-26 00:00:00', '2023-07-27 00:00:00', '2023-07-28 00:00:00', '2023-07-29 00:00:00', '2023-07-30 00:00:00', '2023-07-31 00:00:00')
  AND   BINARY h.vx_mask IN ('WEST')
  AND   BINARY h.model IN ('RRFS_verification_mem000')
  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 = 'AOTK'
  AND ld.stat_header_id = h.stat_header_id
UNION ALL
SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
  obtype,
  fcst_lev,
  vx_mask,
'AOTK' fcst_var,
  'OBAR' stat_name,
  'NA' stat_value,
  ld.total,
  ld.fbar,
  ld.obar,
  ld.fobar,
  ld.ffbar,
  ld.oobar,
 ld.mae
FROM
  stat_header h,
  line_data_sl1l2 ld
WHERE
    BINARY h.obtype IN ('AERONET_AOD')
  AND   BINARY h.fcst_lev IN ('L0')
  AND   BINARY ld.fcst_init_beg IN ('2023-07-02 00:00:00', '2023-07-03 00:00:00', '2023-07-04 00:00:00', '2023-07-05 00:00:00', '2023-07-06 00:00:00', '2023-07-07 00:00:00', '2023-07-08 00:00:00', '2023-07-09 00:00:00', '2023-07-10 00:00:00', '2023-07-11 00:00:00', '2023-07-12 00:00:00', '2023-07-13 00:00:00', '2023-07-14 00:00:00', '2023-07-15 00:00:00', '2023-07-16 00:00:00', '2023-07-17 00:00:00', '2023-07-18 00:00:00', '2023-07-19 00:00:00', '2023-07-20 00:00:00', '2023-07-21 00:00:00', '2023-07-22 00:00:00', '2023-07-23 00:00:00', '2023-07-24 00:00:00', '2023-07-25 00:00:00', '2023-07-26 00:00:00', '2023-07-27 00:00:00', '2023-07-28 00:00:00', '2023-07-29 00:00:00', '2023-07-30 00:00:00', '2023-07-31 00:00:00')
  AND   BINARY h.vx_mask IN ('WEST')
  AND   BINARY h.model IN ('RRFS_verification_mem000')
  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 = 'AOTK'
  AND ld.stat_header_id = h.stat_header_id;

