SELECT
  model,
  ld.fcst_init_beg,
  ld.fcst_valid_beg,
  ld.fcst_lead,
  HOUR(fcst_valid_beg) valid_hour,
'T2' fcst_var,
  'BASER' stat_name,
  IF(ld.baser=-9999,'NA',ld.baser ) stat_value,
  IF(ld.baser_ncl=-9999,'NA',ld.baser_ncl  ) stat_ncl,
  IF(ld.baser_ncu=-9999,'NA',ld.baser_ncu  ) stat_ncu,
  IF(ld.baser_bcl=-9999,'NA',ld.baser_bcl) stat_bcl,
  IF(ld.baser_bcu=-9999,'NA',ld.baser_bcu ) stat_bcu
FROM
  stat_header h,
  line_data_cts ld
WHERE
    BINARY h.model IN ('AI_step06')
  AND HOUR(ld.fcst_valid_beg) IN ('00', '03', '06')
  AND   BINARY h.fcst_var = 'T2'
  AND ld.stat_header_id = h.stat_header_id
  AND ld.baser != -9999;

