sql >> Database >  >> RDS >> Oracle

sql-query om de som te berekenen en de som van vorige rijen toe te voegen

U kunt de volgende zoekopdracht gebruiken

with t1(  dat_dt, credit, debit) as
(
 select date'2019-02-22',10,  5 from dual union all
 select date'2019-02-25',30, 60 from dual union all
 select date'2019-03-10',50, 40 from dual union all
 select date'2019-03-13',100,10 from dual    
)
select max(dat_dt) as "max date",
       sum(credit) as "cr sum",
       sum(sum(credit)) over ( order by to_char(dat_dt,'yyyymm') ) as "progressive credit", 
       sum(debit) as "dr sum",
       sum(sum(debit))  over ( order by to_char(dat_dt,'yyyymm') ) as "progressive debit"
  from t1
 group by to_char(dat_dt,'yyyymm')
 order by to_char(dat_dt,'yyyymm');

met aggregatie per jaar-maand combinatie.

Demo



  1. Ongeldige SQL-fout in kolomnaam

  2. Is er MySQL.. INSERT ... ON DUPLICATE KEY SELECT?

  3. Selecteer tijd tussen twee keer mysql

  4. Verbinding geweigerd met MySQL op laravel en MAMP