根据现有字段的第一部分填充新字段

编程入门 行业动态 更新时间:2024-10-08 13:29:15
本文介绍了根据现有字段的第一部分填充新字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在处理一个数据库项目,其中一项任务是使用字段 course_id 的第一部分填充新创建的字段机构",即HarvardX/CB22x/2013_Spring.所以我需要用第一部分填充机构字段'HarvardX.我怎样才能在 MySQL 工作台中做到这一点?

I am working on a database project and one of the tasks is to populate a newly created field 'institution' with the first portion of the field course_id which is HarvardX/CB22x/2013_Spring. So I need to populate the institution field with the first portion only 'HarvardX. How can I do that in MySQL workbench?

推荐答案

您可以使用 substring_index():

update mytable set institution = substring_index(course_id, '/', 1)

如果您还想提取中间部分和结尾部分,则:

If you want to also extract the middlde part and end part, then:

update mytable set institution = substring_index(course_id, '/', 1), other_col = substring_index(substring(course_id, locate('/', course_id) + 1), '/', 1), more_col = substring_index(course_id, '/', -1)

更多推荐

根据现有字段的第一部分填充新字段

本文发布于:2023-10-31 06:53:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   第一部分

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!