真正基本的mySQL查询 - 替换值

时间:2011-04-08 02:49:53

标签: mysql

这一定非常简单:

在mySQL上 -

更新exp_channel_data

其中entry_id介于10169和10860之间

如果custom_field的值为18

用17替换

有什么想法吗?我真的很挣扎着我的小知识!

2 个答案:

答案 0 :(得分:2)

UPDATE exp_channel_data
SET    custom_field = 17
WHERE  custom_field = 18
AND    entry_id BETWEEN 10169 AND 10860

我实际上不记得是否支持BETWEEN;如果没有:

UPDATE exp_channel_data
SET    custom_field = 17
WHERE  custom_field = 18
AND    entry_id >= 10169
AND    entry_id <= 10860

答案 1 :(得分:0)

UPDATE exp_channel_data 
SET custom_field = 17 
WHERE custom_field = 18 AND entry_id > 10169 AND entry_id < 10860

如果要包含10169和10860,请使用BETWEEN语句。

BETWEEN运算符的功能为'大于或等于'[NUMBER] AND'小于或等于'[NUMBER]。

BETWEEN示例:

UPDATE exp_channel_data 
SET custom_field = 17 
WHERE custom_field = 18 AND entry_id BETWEEN 10169 AND 10860