我有这样的数据:
+--+----------+--------+------+
|Id|class_name|class_id|medals|
+--+----------+--------+------+
|1 |7IPA1 |7 |3 |
|2 |7IPA2 |7 |2 |
|3 |7IPA3 |7 |5 |
|4 |8IPA1 |8 |1 |
|5 |8IPA2 |8 |7 |
|6 |8IPA3 |8 |3 |
+--+----------+--------+------+我希望class_id上的数据是7IPA和8IPA (class_name的4个第一个字符)。
发布于 2016-09-02 18:10:29
您必须使用substring函数:
UPDATE MYTABLE SET CLASS_ID=SUBSTRING(CLASS_NAME,1,4)发布于 2016-09-02 18:22:38
另一种方法是使用LEFT字符串函数
Select LEFT(CLASS_NAME,4) from yourtable看起来您想要一个新列,而不是更新现有列,我建议您创建一个计算列
alter table yourtable add new_class_id as (left(class_name,4)) persisted https://stackoverflow.com/questions/39289712
复制相似问题