Skip to main content
added 1 character in body
Source Link

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that thethey occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

You can even look for repetitions of various length, here 2 and 3:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
     , count(1) over (partition by details, lead_details, lead2_details) cnt2
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
     , lead(details,2) over (order by id) as lead2_details
    from eventLog
  ) as t
) as tt
where cnt > 1
 or cnt2 > 1;

db<>fiddle

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that the occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

You can even look for repetitions of various length, here 2 and 3:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
     , count(1) over (partition by details, lead_details, lead2_details) cnt2
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
     , lead(details,2) over (order by id) as lead2_details
    from eventLog
  ) as t
) as tt
where cnt > 1
 or cnt2 > 1;

db<>fiddle

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that they occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

You can even look for repetitions of various length, here 2 and 3:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
     , count(1) over (partition by details, lead_details, lead2_details) cnt2
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
     , lead(details,2) over (order by id) as lead2_details
    from eventLog
  ) as t
) as tt
where cnt > 1
 or cnt2 > 1;

db<>fiddle

added 660 characters in body
Source Link

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that the occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

db<>fiddle You can even look for repetitions of various length, here 2 and 3:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
     , count(1) over (partition by details, lead_details, lead2_details) cnt2
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
     , lead(details,2) over (order by id) as lead2_details
    from eventLog
  ) as t
) as tt
where cnt > 1
 or cnt2 > 1;

db<>fiddle

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that the occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

db<>fiddle

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that the occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

You can even look for repetitions of various length, here 2 and 3:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
     , count(1) over (partition by details, lead_details, lead2_details) cnt2
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
     , lead(details,2) over (order by id) as lead2_details
    from eventLog
  ) as t
) as tt
where cnt > 1
 or cnt2 > 1;

db<>fiddle

added 521 characters in body
Source Link

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

db<>fiddle If you don't care for which details that are consecutive, merely that the occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

db<>fiddle

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

db<>fiddle

You can use OLAP or window functions. Example for details, you can add a derived column for type as well:

 select *
 from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
 ) as t
 where t.details = 'power on' and t.lead_details = 'cleaning started'
  ;

If you want a more generic solution, you can add a table that contains consecutive pairs that you are interested in, and use that in your query

If you don't care for which details that are consecutive, merely that the occur several times:

select id, type, details, lead_id, lead_details
from (  
  select id, type, details, lead_id, lead_details
     , count(1) over (partition by details, lead_details) cnt
  from (  
    select id, type, details
     , lead(id) over (order by id) as lead_id
     , lead(details) over (order by id) as lead_details
    from eventLog
  ) as t
) as tt
where cnt > 1;

db<>fiddle

edited body
Source Link
Loading
Source Link
Loading