Select previous value in row without using a subquery Say you have a table in PostgreSQL 11 with sets of values something like this below.

12 18
11 12
5  12
9  18
7  19
14 18
11 16
6  12
4  11
5  9


Is there a way to do a select without using sub-selects or select by using functions or trigger/functions to find where each value is lower than previous or could be higher than previous but this example is lower than previous (could be 2 row or 15+ rows) in both column and first column went higher than last row or both first and second column to terminate the select making the condition positive?

I do not know of a way to have present variables inside of a select.  If I could keep a look back variable then I should be able to do this.  I am wondering if anyone out there has ever come across this and made it work inside a select or they went outside of the database into GoLang / Python / C++ / Perl / PHP / etc.  Very simple to do once I leave the database but I would really like to keep this inside PostgreSQL 11.
As Akina has pointed out in comments LAG() function requires an ORDER BY clause to show the properly values.

Given the next example:

CREATE TABLE t (id int, bar int);

INSERT INTO t VALUES
(1, 7),
(2, 8),
(3, 30),
(4, 25),
(5, 24),
(6, 24),
(7, 35),
(8, 40);


You can get the previous bar value ordering by id, (if you don't set an order, what is the previous row?)

SELECT
    id,
    bar,
    LAG(bar) OVER (ORDER BY id)
FROM
    t;

id | bar |  lag
-: | --: | ---:
 1 |   7 | null  --&lt;&lt; Note the NULL value
 2 |   8 |    7
 3 |  30 |    8
 4 |  25 |   30
 5 |  24 |   25
 6 |  24 |   24
 7 |  35 |   24
 8 |  40 |   35


Then simply use a conditional statement IF or CASE

SELECT
    id,
    bar,
    CASE 
        WHEN LAG(bar) OVER (ORDER BY id) &lt; bar THEN 'Lower'
        WHEN LAG(bar) OVER (ORDER BY id) &gt; bar THEN 'Higher'
        WHEN LAG(bar) OVER (ORDER BY id) = bar THEN 'Equal'
        ELSE 'Nothing to compare'
    END As Previous
FROM
    t;

id | bar | previous          
-: | --: | :-----------------
 1 |   7 | Nothing to compare
 2 |   8 | Lower             
 3 |  30 | Lower             
 4 |  25 | Higher            
 5 |  24 | Higher            
 6 |  24 | Equal             
 7 |  35 | Lower             
 8 |  40 | Lower            


db&lt;>fiddle here