这里是编码/SQL 新手,当我尝试更改 mysql 工作台上的以下列(表名称:train)时遇到问题:
我想调整这一栏,因为“条件”太重复了。所以我想只取出此列中必要的信息,将数据复制到新列“天气”,然后通过执行以下操作删除原始列:
SELECT trim(substr(Weatherconditions, 11)) AS Weather FROM train;
ALTER TABLE train
ADD Weathers Varchar(255)
UPDATE train
SET Weathers = select trim(substr(Weatherconditions, 11)) as Weather from train
ALTER TABLE train
DROP Weatherconditions
并且我在更新语句中遇到错误。我该如何修改这段代码? 或者还有另一种方法可以通过拆分列来实现相同的目的?
塔!
我尝试过 substring 语句,但也出现错误。因此需要了解如何正确执行此操作。
您的更新语句末尾有无关的
FROM
和 SELECT
子句,这些子句不属于那里。变化:
UPDATE train SET Weathers = SELECT TRIM(SUBSTR(Weatherconditions, 11)) AS Weather FROM train
至:
UPDATE train SET Weathers = TRIM(SUBSTR(Weatherconditions, 11))