gpt4 book ai didi

mysql - 在 SQL 中反转字符串

转载 作者:行者123 更新时间:2023-11-29 06:41:11 25 4
gpt4 key购买 nike

我有一个 sql 问题。我有一个表,其中包含一个名为 title 的列,该列在所有 raws 中存储这样的字符串。

"Prenom - Nom (85)".

我想知道在 sql 中是否有一种方法可以像这样更改该字符串:

"Nom - Prenom" 

这意味着,我想反转它,然后删除"(85)。

提前谢谢你。

最佳答案

是的:

select concat(substring_index(left(col, length(col) - instr(reverse(col), ' ')), ' - ', -1),
' - ',
substring_index(col, ' - ', 1)
)

这假设您想要一些比摆脱 '(85)' 更通用的东西;它删除了最后一个词。

关于mysql - 在 SQL 中反转字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21479161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com