Oracle
 sql >> Base de données >  >> RDS >> Oracle

récupérer plusieurs colonnes grouper par intervalle de date

Pour moi, ça ressemble à ça :

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 d'autres termes, vérifiez si le jour de scale_eventdate la colonne appartient à la 1ère ou à la 2ème moitié du mois et la somme scale_weight en conséquence.