I have issue. I try to do one If-Else, In postgresql. I have 2 colums. "measure" is the measurements INT, and the another column is the "Status" boolean. Both on different table. The query simple, If the measurement more than 100 then change the "Status_SG" true. I lerned Sql but not this deep, and now I stuck.
Checked online many option but non of them works.
CodePudding user response:
Hope this can solve the problem .
SELECT
CASE WHEN (a.intcol > 100) AND b.booleancol THEN 'message1' ELSE 'message2' END
FROM table AS a
JOIN table2 AS b ON a.id = b.id
CodePudding user response:
I do like this:
SELECT "measurements_column", "Status_column" CASE WHEN ("measurements_column" > 100) AND "Status_column" THEN 'message1' ELSE 'message2' END FROM "measurementColumnTable" AS a JOIN "StatusColumnTable" AS b ON "measurementsID" = "StatusID"
But give me error message:
SQL-Error [42601]: ERROR: syntax error at or near "CASE" Position: 27