How to use windowing functions to find gaps in sequences grouped by a column, in PostgreSQL
You should use a CTE or a subquery to get the lead order_no first.




select client_id,
       order_no + 1 as c1,
       no - 1 c2
from   (select client_id, 
               order_no,
               lead(order_no) 
                   over (partition by client_id order by client_id, order_no) as no
from     tbl) ct
where  no is not null
and    no - order_no &gt; 1;






with ct as
(
select   client_id, 
         order_no,
         lead(order_no) 
             over (partition by client_id order by client_id, order_no) as no
from     tbl
)
select client_id,
       order_no + 1 as c1,
       no - 1 c2
from   ct
where  no is not null
and    no - order_no &gt; 1;



client_id | c1 | c2
--------: | -: | -:
       43 |  2 |  4



db&lt;>fiddle here