Oracle SQL - How to contrain related records timewise
<p>Given the below listed data, how to select only records, for which:</p>

<p>a) at least 1 previous ticket for the same client_id exists and</p>

<p>b) the maximum time difference of each predecessing ticket may not exceed 14   days. In other words, if a ticket has a successor as described in a) and this successor has been created >14 days later, it must not be considered.</p>

<pre><code>create table tickets (
ticket_id number,
client_id number,
start_time date);

insert into tickets values (1,1,to_date('201601011330','yyyymmddhh24mi'));
insert into tickets values (2,1,to_date('201601021320','yyyymmddhh24mi'));
insert into tickets values (3,1,to_date('201601101330','yyyymmddhh24mi'));
insert into tickets values (4,1,to_date('201603101330','yyyymmddhh24mi'));
insert into tickets values (5,2,to_date('201601011630','yyyymmddhh24mi'));
insert into tickets values (6,2,to_date('201601201330','yyyymmddhh24mi'));
insert into tickets values (7,3,to_date('201602011330','yyyymmddhh24mi'));
insert into tickets values (8,4,to_date('201602290000','yyyymmddhh24mi'));
insert into tickets values (9,4,to_date('201603011630','yyyymmddhh24mi'));
insert into tickets values (10,4,to_date('201604011120','yyyymmddhh24mi'));
insert into tickets values(11,4,to_date('201604101030','yyyymmddhh24mi'));
commit;
</code></pre>