gpt4 book ai didi

`() ' "` 等字符的字符串数据的Mysql列排序

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

我有一个表,它包含 varchar 数据。该列中的数据是这样的。

"bcd"
cde
abcd
'xxx'
(zzz)

现在我想按字母顺序排序。我试过这个查询

select my_col from tbl_user order by ltrim(REPLACE(my_col,'"', '')) ASC

它的输出如下:

'xxx'
(zzz)
abcd
"bcd"
cde

但我想要的输出是,意味着在排序时它必须根据字母顺序排序,无论 " 是否存在。

abcd
"bcd"
cde
'xxx'
(zzz)

我怎样才能做到这一点??。任何想法。

最佳答案

尝试多个REPLACE

ORDER BY REPLACE(REPLACE(REPLACE(REPLACE(my_col,'"', ''), '(',''), ')', ''), '''','') ASC

SQLFiddle Demo

关于 `() ' "` 等字符的字符串数据的Mysql列排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12796698/

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