АВ
Size: a a a
АВ
D
ДУ
ДГ
DC
D
select tgtdate, domainname, groupArray(ns),
if(count(ns)=sum(deleted), 1,0) as isdeleted,
if(count(ns)=sum(added), 1,0) as isadded,
if(count(ns)!=sum(notchanged) and not isadded and not isdeleted, 1,0) as ismodified
from
(
select all_dates[2] as tgtdate, domainname, ns,
--- use for troubleshooting
groupArrayInsertAt('none', 2)(ns, toUInt32(indexOf(all_dates, dt) - 1)) arrData,
If( (countIf(dt=toDate('2020-01-09')) as existsYesterday ) and not (countIf(dt=toDate('2020-01-10')) as existsToday),1,0 ) as deleted,
If( (not existsYesterday) and existsToday,1,0 ) as added,
If( existsYesterday and existsToday,1,0 ) as notchanged
--arrayElement(groupArrayInsertAt(Null, 2)(tuple(toNullable(ns)), toUInt32(indexOf(all_dates, toDate(datadatetime)) - 1)).1 as values, 1) as "daybefore",
from (
with [ toDate('2020-01-09'), toDate('2020-01-10') ] as all_dates
select dt, domainname, ns, all_dates
from
(
-- this is generated sample data
select dt, domainname, arraySort(x-> x, groupArray(NS)) sortedNSList from (
select toDate('2020-01-08') +cityHash64(number,3)%4 as dt, 'ns'|| toString(cityHash64(number,0)%5) as NS, toString(cityHash64(number%25,1)) domainname from numbers(100)
) group by dt, domainname order by dt
) array join sortedNSList as ns
where 1=1
-- and domainname='10497707425991577777'
and dt in (all_dates)
) group by tgtdate, domainname, ns
)
group by tgtdate, domainname;
D
D
D
D
D
D
D
ДУ
D
D
D
D
D
ДУ