use zzz_999;

  select
      *  
  from (              
        select 
          s.di_source_id, s.brand_sku_id,
          date_format('2024-01-01','%Y-%m-%d') as adjusted_dtm,
          0 as is_sit,
          0 as sit_uom, 
          sum(s.volume / 9000) / ( datediff('2023-12-31', '2023-12-01') +1) as sales_uom_daily_average
        from colstore_zzzzzz_zzz_999999 s
        where s.di_source_id in (5129,5133,5136,5137,5156,5225,5226,5227,5228,5231,5245,5249,5251,5253,5269,5273,5277,5278,5279,5280,5281,5285,5293,5294,5296,5297,5298,5299,5300,5301,5302,5303,5304,5307,5312,5319,5379,5380,5389)
        and s.brand_sku_id = 1004    
        and (s.yyyymmdd >= '2023-12-01' and s.yyyymmdd <= '2023-12-31')
        group by 1,2,3
                union
      select
        s.di_source_id, s.brand_sku_id,
        date_add(s.yyyymmdd, interval (case when day(yyyymmdd ) < 15 then (day(yyyymmdd ) - 1)*-1 else (day(last_day(yyyymmdd )) - day(yyyymmdd )) +1 end)  day) as adjusted_dtm,
        1 as is_sit,
        sum(s.volume / 9000) as sit_uom, 0 as sales_uom_daily_average
      from zzz_999999 s
      where date_add(yyyymmdd, interval (case when day(yyyymmdd ) < 15 then (day(yyyymmdd ) - 1)*-1 else (day(last_day(yyyymmdd )) - day(yyyymmdd )) +1 end)  day)  = '2024-01-01'
      and s.brand_sku_id = 1004                        
      group by 1,2,3,4
                
  
  ) as z;