MySQL IF语句,IF SET,ELSE 什么也不做?

14 浏览
0 Comments

MySQL IF语句,IF SET,ELSE 什么也不做?

这个问题已经有了答案:

\'IF\' in \'SELECT\' statement - choose output value based on column values

我一直在以下语句中遇到语法错误。

这是我目前的代码,但似乎不起作用。

IF(birthday_year='0', birthday_year='0001', birthday_year)

如果birthday_year的值为0,则将其设置为0001; 否则(如果它不是0,并且是另一个值),则保留该值; 如果它不是0,则不更改该值。

admin 更改状态以发布 2023年5月21日
0
0 Comments

语法非常简单:IF(条件, 真值, 假值),因此非常简单;

SELECT IF(birthday_year='0', '0001', birthday_year) birthday_year
FROM ... 

0
0 Comments

如果你想要更新表格,这是你要做的:

UPDATE table1 SET birthday_year = '0001' 
WHERE birthday_year = '1'

你真正只在存储过程里使用IF语句。

见:google
更具体地: http://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843

虽然你可以在select里使用IF语句,但这确实不太合理。你最好使用wherecase语句。

0