[英]substring_index in replace mysql
可以说我有这样的句子
id sentence
1. I LOVE ORANGE 300G, and i want that Orange 300G
2. I HATE STRAWBERRY 500G, and i want that Strawberry 500G
3. i love the orange 300G (with that big), and i want that orange 300G (with that big)
我想删除每个句子的最后一个索引,所以预期的结果应该是这样的
I LOVE ORANGE 300G, and i want that Orange
I HATE STRAWBERRY 500G, and i want that Strawberry
i love the orange 300G (with that big), and i want that orange (with that big)
我试过这个
SELECT REPLACE(mytable.sentence, substring_index(mytable.sentence, '', -1), '') AS meta_keywords2 FROM mytable
但由于最后一个索引在 1 个句子中总是与另一个相同,结果是这样的:
I LOVE ORANGE, and i want that Orange
I HATE STRAWBERRY, and i want that Strawberry
这是一个想法:
SELECT SUBSTRING(mytable.sentence, 1, LENGTH(mytable.sentence)-LENGTH(SUBSTRING_INDEX(mytable.sentence, ' ', -1))) AS meta_keywords2
FROM mytable;
LENGTH()
。sentence
的总LENGTH()
。1
开头的sentence
上使用SUBSTRING()
并提取总长度和最后一个单词长度之间的总字符差。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.