zOs/SQL/GBGRSPHC

     -- table Space und Details History / Zeitreihe
set current path oa1p;
with d (d,l) as
(
  select date('31.12.2014'), 0
    from sysibm.sysDummy1
  union all select d - 1 year, l+1
    from d
    where l < 999999 and d >= current date - 4 years
)
, t1 as
(
   select rz, dbSys, dbName, name, instance, partition
    from oa1p.tqz006GbGrTsSTats
 -- where rz = 'RZ2'    and dbSys = 'DBOF'
 --       and  dbName like 'XR%'
     --   and name like 'A250%'
    group by rz, dbSys, dbName, name, instance, partition
)
, t2 as
(
  select d.d, t1.*, (select max(loadTs) from oa1p.tqz006GbGrTsSTats r
    where t1.rz = r.rz and t1.dbSys = r.dbSys
          and  t1.dbName = r.dbName
          and  t1.name = r.name
          and  t1.instance = r.instance
          and  t1.partition = r.partition
          and loadTs < timestamp(d.d + 1 day)
    ) loadTs
    from t1, d
)
, t as
(
   select d, r.*
     from t2
      join oa1p.tqz006GbGrTsSTats r
        on t2.loadTS is not null and r.state <> 'd'
                and t2.rz        = r.rz
                and t2.dbSys     = r.dbSys
                and t2.dbName    = r.dbName
                and t2.name      = r.name
                and t2.instance  = r.instance
                and t2.partition = r.partition
                and t2.loadTs    = r.loadTS
)
, g as
(
  select rz, dbSys, d
      , count(distinct dbName) cDb
      , count(distinct strip(dbName) || '.' || strip(name)) cTs
      , count(*) cPart
      , sum(real(nActive) * pgSize * 1024) used
      , sum(totalRows) rows
      , max(loadTs) loadMax
      , min(loadTs) loadMin
      , max(updateStatsTime) updMax
      , min(updateStatsTime) updMin
    from t
    group by rz, dbSys, d
)
, g1 as
(
  select rz, '*' dbSys, d
      , sum(cDb) cDb, sum(cTs) cTs, sum(cPart) cPart
      , sum(used) used, sum(rows) rows
      , max(loadMax) loadMax, min(loadMin) loadMin
      , max(updMax) updMax, min(updMin) updMin
    from g
    group by rz, d
)
, u as
(
   select * from g
   union all select * from g1
)
select rz, dbSys, date(loadMax) loadMax, cDb, cTs, cPart
      , int(round(used, 0) / 1024 / 1024 / 1024) "usedGB"
      , int(round(rows, 0) / 1000000) "rowsM"
  --  , d
  --  , date(loadMax) loadMax, date(loadMin) loadMin
  --  , date(updMax) updMax, date(updMin) updMin
    from u
    order by case when dbSys = '*' then 0 else 1 end, rz, dbSys, d desc
;