zOs/SQL/GBGRMISE

select rz, dbSys, state, count(*) count
, sum(case when updateSTatsTime < loadTs      then 1 else 0 end) "u<l"
, sum(case when updateSTatsTime = loadTs      then 1 else 0 end) "u=l"
, sum(case when updateSTatsTime > loadTs      then 1 else 0 end) "u>l"
, sum(case when updateSTatsTime<origStatsTime then 1 else 0 end) "u<o"
, sum(case when updateSTatsTime=origStatsTime then 1 else 0 end) "u=o"
, sum(case when updateSTatsTime>origStatsTime then 1 else 0 end) "u>o"
, sum(case when origStatsTime < loadTs        then 1 else 0 end) "o<l"
, sum(case when origStatsTime = loadTs        then 1 else 0 end) "o=l"
, sum(case when origStatsTime > loadTs        then 1 else 0 end) "o>l"
, sum(case when year(updateSTatsTime) <1911 then 1 else 0 end) "u<1911"
, sum(case when year(updateSTatsTime) <2000 then 1 else 0 end) "u<2000"
, sum(case when year(updateSTatsTime) <2015 then 1 else 0 end) "u<2015"
, sum(case when year(updateSTatsTime) =2015 then 1 else 0 end) "u=2015"
, sum(case when year(updateSTatsTime) =2016 then 1 else 0 end) "u=2016"
, sum(case when year(updateSTatsTime) >2016 then 1 else 0 end) "u>2016"
  from oa1p.tqz667gbgrIxStats a
 --  where a.rz='RZZ' -- and a.dbSys = 'DBOF'
   --  and loadTS > '2016-01-05-08.53.52.138027'
  group by rz, dbSys, state
;x;
select rz, dbSys, state, count(*) count
, sum(case when updateSTatsTime < loadTs      then 1 else 0 end) "u<l"
, sum(case when updateSTatsTime = loadTs      then 1 else 0 end) "u=l"
, sum(case when updateSTatsTime > loadTs      then 1 else 0 end) "u>l"
, sum(case when updateSTatsTime<origStatsTime then 1 else 0 end) "u<o"
, sum(case when updateSTatsTime=origStatsTime then 1 else 0 end) "u=o"
, sum(case when updateSTatsTime>origStatsTime then 1 else 0 end) "u>o"
, sum(case when origStatsTime < loadTs        then 1 else 0 end) "o<l"
, sum(case when origStatsTime = loadTs        then 1 else 0 end) "o=l"
, sum(case when origStatsTime > loadTs        then 1 else 0 end) "o>l"
, sum(case when year(updateSTatsTime) <1911 then 1 else 0 end) "u<1911"
, sum(case when year(updateSTatsTime) <2000 then 1 else 0 end) "u<2000"
, sum(case when year(updateSTatsTime) <2015 then 1 else 0 end) "u<2015"
, sum(case when year(updateSTatsTime) =2015 then 1 else 0 end) "u=2015"
, sum(case when year(updateSTatsTime) =2016 then 1 else 0 end) "u=2016"
, sum(case when year(updateSTatsTime) >2016 then 1 else 0 end) "u>2016"
  from oa1p.tqz666gbgrTsStats a
 --  where a.rz='RZZ' -- and a.dbSys = 'DBOF'
   --  and loadTS > '2016-01-05-08.53.52.138027'
  group by rz, dbSys, state
;x;
with u as
( select rz, dbSys, dbName, ts, indexSpace, partition, instance
  from oa1p.tqz667gbgrIxStats a
  where -- a.rz='RRZ' -- and a.dbSys = 'DBOF'
       loadTS > '2016-01-05-14.53.52.138027'
       and state = 'd'
)
select *
  from oa1p.tqz667gbgrIxStats a
  where updateStatsTime > current timestamp - 555 days
    and (rz, dbSys, dbName, ts,indexSpace,partition, instance)
    in (select * from u)
  order by rz, dbSys, dbName, ts, indexSpace, partition, instance
      , updateSTatsTime desc
;X;
with u as
( select rz, dbSys, dbName, name,partition, instance
  from oa1p.tqz666gbgrTsStats a
  where a.rz='RZZ' -- and a.dbSys = 'DBOF'
       and loadTS > '2016-01-05-08.53.52.138027'
       and state = 'd'
)
select *
  from oa1p.tqz666gbgrTsStats a
  where loadTs > current timestamp - 5 days
    and (rz, dbSys, dbName, name,partition, instance)
    in (select * from u)
  order by rz, dbSys, dbName, name,partition, instance
      , updateSTatsTime desc
;X;
select rz, dbSys, state, count(*) count
  , sum(case when updateSTatsTime = origStatsTime then 1 else 0 end) or
  , sum(case when updateSTatsTime = loadTs        then 1 else 0 end) lo
  , sum(case when updateSTatsTime > loadTs        then 1 else 0 end) gt
  , sum(case when date(updateSTatsTime) = current date
               then 1 else 0 end) today
  , sum(case when date(updateSTatsTime) = current date - 1 day
               then 1 else 0 end) yestr
  , sum(case when updateSTatsTime < '1911-11-11-11.11.11'
               then 1 else 0 end) l11
  from oa1p.tqz666gbgrTsStats a
  where a.rz='RZZ' -- and a.dbSys = 'DBOF'
       and loadTS > '2016-01-05-08.53.52.138027'
  group by rz, dbSys, state
;x;
select *
  from oa1p.tqz666gbgrTsStats a
  where a.rz='RR2' -- and a.dbSys = 'DBOF'
       and loadTS > '2016-01-05-09.00.00.138027'
 fetch first 100 rows only
;x;