更新 - 其中使用文本的子句未按预期响应



我有一个表,其中包含一个名为"time_source"的列,具有五个潜在值:

"型号"、"country_city"、"区域"、"更新"和"存储">

我一直在尝试制作一个更新语句,如果time_source是这样的"模型",该语句将不会更新列date_destination:

update t_vessel_list_ballast
set date_destination = date_depart + voyage_time
where time_source not like 'model';

但它并没有像我预期的那样工作。 相反,即使"模型"在time_source中,它也会覆盖date_destination。我尝试了这样的事情:

update t_vessel_list_ballast
set date_destination = date_depart + voyage_time
where time_source like 'country_city'
or time_source like 'region';

但我仍然得到相同的结果。

模型中没有其他地方可以发生这种情况。

为什么我没有得到我期望的结果?我如何解决这个问题以获得我想要的东西?

我认为使用like,如果您想匹配行(或者不像这里那样匹配行(,您还需要在模式上%s 以显示在哪里匹配任何其他字符。例如like '%match'将匹配任何以match结尾的字符串,而like 'match%'将匹配以 match 开头的字符串。您还可以将它们组合在一起以匹配包含 match 的字符串与like '%match%'.

最新更新