简体   繁体   中英

count substring_index

i need to know how substring_index can only return all rows that match exactly the number of delimiters. 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):

aaa.bbb.ccc.ddd

The problem is that: this row is also showed .

aaa.bbb

This will return anything where ABC has 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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