PostgreSQL: Convert 0 to 1 and 1 to 0
In PostgreSQL, you can convert 0 to 1 and 1 to 0 using these methods:
- Using CASE Expression:
SELECT CASE WHEN column_name = 0 THEN 1 ELSE 0 END AS converted_value
FROM your_table;
- Using Mathematical XOR Operator:
SELECT column_name # 1 AS converted_value
FROM your_table;
Both methods effectively achieve the desired conversion between 0 and 1.
原文地址: https://www.cveoy.top/t/topic/o9aE 著作权归作者所有。请勿转载和采集!