简体   繁体   English

count substring_index

[英]count substring_index

i need to know how substring_index can only return all rows that match exactly the number of delimiters. 我需要知道substring_index如何只返回与分隔符数完全匹配的所有行。 In this case the . 在这种情况下.

For example this query: 例如这个查询:

 SELECT
 SUBSTRING_INDEX(ABC, '.', 4)
 FROM xxx

only should output when the row is exactly something like this (with 4 words): 只有当行完全像这样(有4个单词)时才输出:

aaa.bbb.ccc.ddd

The problem is that: this row is also showed . 问题是:这一行也显示出来。

aaa.bbb

This will return anything where ABC has 3 . 这将返回ABC有3的任何内容. delimiters. 分隔符。

select *
from xxx
where char_length(replace(ABC, '.', '')) + 3 = char_length(ABC)

You would need to multiply 3 by your delimiter length if you had a multi-character string for your delimiter. 如果您的分隔符有多字符字符串,则需要将3乘以分隔符长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM