0

I am new to (Postgre)SQL and have the following question: I have a small relation in a database of scheme (c1: varchar(1), c2:integer, c3: varchar(1), c4: integer). Column 1 (c1) always contains 'a' and column 3 (c3) always contains 'b'. Columns 2 and 4 contain integers that are not equal to each other.

What I want to do is to write a query to the database that returns the scheme as explained above with one more column that contains 'a' if the value of c2 is greater then the value in c4 and which otherwise returns 'b'. How would I do that? (I suppose one has to use if in the head of select, but I do not know how).

For example, this would be a desired output

c1 c2 c3 c4 newColumn
a 5 b -3 a
a 4 b 7 b
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
sorry
  • 115
  • 3
  • Ok, I have a solution here: https://stackoverflow.com/questions/13526592/using-if-else-in-sql-select-statement#13526616 – sorry Feb 15 '22 at 16:15

0 Answers0