sql >> Base de Datos >  >> RDS >> Oracle

recuperar varias columnas agrupadas por intervalo de fecha

Para mí, se ve así:

select 
  sum(case when b.materialid = 1 and
                to_number(to_char(b.scale_eventdate, 'dd')) between  1 and 15 then 
                b.scale_weight 
      end) mtrl1,
  --      
  sum(case when b.materialid = 2 and
                to_number(to_char(b.scale_eventdate, 'dd')) between 16 and 31 then 
                b.scale_weight 
      end) mtrl2
from datalog_tab b
where to_char(b.scale_eventdate, 'yyyymm') = '202010' 
  

En otras palabras, verifique si el día de scale_eventdate la columna pertenece a la 1.ª o 2.ª mitad del mes y suma scale_weight en consecuencia.