选择字符串中的所有字符,直到特定字符MySQL [英] Select all characters in a string until a specific character MySQL

查看:84
本文介绍了选择字符串中的所有字符,直到特定字符MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL数据库中有一条记录,如下所示:

I have a record in an SQL database that looks like this:

'839af0d3-9301-33d0-abce-e16a673980fd', 'Aforic', '7:74324:35:4:1:1203:348:27:415:158:2:0:0:0D-5H-17M-26S', 'Tactician', ' '

该表的定义如下:

`T1` (`player_uuid`, `player_name`, `stats`, `inventory`, `selected`) 

如何编写查询以仅从统计信息"中选择名称和第一个条目.基本上,我只想选择统计"中:"之前的第一个条目.在这种情况下,它将是7.

How do I write a query to select only the name and the first entry from "stats". Basically, I only want to select the first entry in "stats" that is before ":". In this case, it would be 7.

谢谢!

推荐答案

使用在前三个:分隔符之间分割值,

Splitting the values between the first 3 : delimiters,

select player_name
,substring_index(stats,':',1) as col_1
,substring_index(substring_index(substring_index(stats,':',3),':',-2),':',1) as col_2
,substring_index(substring_index(stats,':',3),':',-1) as col_3
from T1

这篇关于选择字符串中的所有字符,直到特定字符MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆