Skip to content
Advertisement

check for same range in postgresql

I wanted to check if for one particular student my column (Amount) contains a value less than 10, and if yes, then check if for the same student my column (Amount) is also greater than 10 and update the column new accordingly in PostgreSQL.

MY table:

x

Tried this way but not working

The output I’m expecting:

y

Advertisement

Answer

One option is to self-join the table with an aggregate subquery, and then do a conditional assignment in the outer query:

Demo on DB Fiddle:

name  | amount | new     
:---- | :----- | :-------
Harry | 3      | pass    
Harry | 50     | pass    
Ron   | 5      | not pass
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement