I want to return a preview of my texts by getting the first 10 words.
我想通过前10个单词来预览我的文章。
concat(SUBSTRING_INDEX(q.value, ' ', 10), '...') AS preview
this works great when the string is long. But it should not be added when the string is shorter (because there is nothing more).
当绳子很长时,这个效果很好。但当字符串较短时,不应该添加它(因为没有其他内容了)。
Is it possible to do this with 100% mysql?
可以用100%的mysql吗?
1 个解决方案
#1
4
You can use case
:
你可以用例:
select (case when substring_index(q.value, ' ', 10) = q.value
then q.value
else concat(substring_index(q.value, ' ', 10), '...')
end)
#1
4
You can use case
:
你可以用例:
select (case when substring_index(q.value, ' ', 10) = q.value
then q.value
else concat(substring_index(q.value, ' ', 10), '...')
end)