Это сделает свое дело
with cte as
(
select
i.*
from
localInput as i
outer APPLY
getarrayelements(i.flags) ae
where
ae.ArrayValue != 'Ignore'
or
getarraylength(i.flags) = 0
)
select
c.id,
c.device,
c.flags
from
cte c
group by
c.id,
c.device,
c.flags,
System.Timestamp
having
count(*) = getarraylength(c.flags)
or
getarraylength(c.flags) = 0
Я проверил это на следующих данных:
{"device":"TestDevice1","id":1,"flags":[ "New", "Ignore"]}
{"device":"TestDevice2","id":2,"flags":[ "New"]}
{"device":"TestDevice3","id":3,"flags":[ "Ignore"]}
{"device":"TestDevice2","id":4,"flags":[ "Something", "Else"]}
{"device":"TestDevice2","id":5,"flags":[]}