以下WHEN THEN
适用于PostgreSQL
,
SELECT
CASE WHEN ab.col1='NULL' THEN ab.col2 ELSE ab.col1 END as col
FROM table1 as ab
我需要在声明中添加ELSE IF
,因此我尝试按以下方式转换为简单IF THEN
,
SELECT
IF ab.col1='NULL' THEN ab.col2 ELSE ab.col1 END IF as col
FROM table1 as ab
但这会产生错误,
ERROR: syntax error at or near "."
LINE 2: IF ab.col1='NULL' then ab.col2 ELSE ab.col1...
^
SQL state: 42601
Character: 13
你能帮我解决一下吗?
答案 0 :(得分:0)
你需要这样做:
SELECT
CASE WHEN ab.col1 IS NULL THEN ab.col2
ELSE ab.col1 END as col
FROM table1 as ab;
你不确定NULL真的是一个字符串......或者你可以这样做:
#!/bin/sh
###### STARTING UP NRF MODULE #####
sleep 2
pushd Desktop/RPI_GATEWAY/NRF24L01
terminal -e python NRF_MQTT.py
pwd
sleep 5
###################################
#### STARTING UP TEST MODULE 1 ####
pushd Desktop/RPI_GATEWAY/TEST
terminal -e python TEST_PUB_1.py
sleep 2
pwd
###################################
#### STARTING UP TEST MODULE 2 ####
pushd Desktop/RPI_GATEWAY/TEST
terminal -e python TEST_PUB_2.py
sleep 2
pwd
###################################
希望这会有所帮助。