mysql - 如何编写我的 sql 查询来拆分列?
问题描述
我在 MySQL 中有一个表
aaa 1234555 asdasdvad
asdasdada 4564456 as
asdadw 8547965 asdasdasd
_________________________
我想通过拆分数字和字母将它拆分为两列,就像
t1 t2
_________________ _______________
aaa asdasdvad 1234555
asdasdada as 4564456
asdadw asdasdasd 8547865
我如何编写一个 sql 查询来做到这一点
任何帮助,将不胜感激
解决方案
我们可以SUBSTRING_INDEX
毫不费力地做到这一点:
SELECT
CONCAT(SUBSTRING_INDEX(col, ' ', 1), ' ', SUBSTRING_INDEX(col, ' ', -1)) AS t1,
SUBSTRING_INDEX(SUBSTRING_INDEX(col, ' ', 2), ' ', -1) AS t2
FROM yourTable;
演示
但是,这个答案实际上只是假设您希望将第一项和第三项连接在一起作为一列,并将中间项作为第二列。我不努力检查数字、字母等。
推荐阅读
- python - 内联表单集导致错误:“NoneType”对象没有属性“is_ajax”
- gephi - 如何在 Gephi 图上应用 METIS 分区
- swift - 如何在 swift 中将委托值添加到 tableview
- c# - 从 libgit2sharp 中的 git 配置中获取用户的身份/签名以进行提交
- python - 想要在第 3 列中识别具有相同值的行并将它们分组到输出中
- r - 过滤包含重要单核苷酸多态性的基因
- saml-2.0 - 单点注销如何与 OKTA(IDP)-Shibboleth(SP)-App 配合使用
- java - 如何在 Spring Boot 中对两个实体进行内部连接?
- javascript - 用于匹配第一个单词的正则表达式
- autodesk-forge - 尝试使用 Autodesk Forge ReCap API 重建特定数量的图像时出错