Q:

Fill or inserting new field based on comparison of two other field

I have a layer Network with two different columns 
Route and section

I need a query or function that compare Route rows , and section rows, and create or rather fill the new_field with this condition:
IF(route.row=route.row-1;"newfieldvalue"=1;
IF(section.row=section.row-1;"newfield_value"+1;1))

This Query or function should compare each Coloumn with it selfs that mean:
If the row value of Route is equal to the one above; and if the row value of section couloumn is equal to the one above than insert( @current value of new field + 1) else 1;

A:

There are two reasonable options:

window functions, namely the lag(<column_value>,  <row_offset>, <default_value>) function that returns the <column_value> at the  (specified or 1.) row before the current row, or, if no such row exists, the <default_value> (specified or NULL)
a table JOIN LATERAL with itself, selecting the row with <row_number - 1> for each row passed to the join query

In both cases it's substantial to provide a ORDER BY <value> clause (for window functions in OVER()) to get meaningful references to neighboring rows.

There's still no relation to spatial data here, making this off-topic for this board...

