Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
substring_index区切り文字の数と正確に一致するすべての行のみを返す方法を知る必要があります。この場合、.
substring_index
.
たとえば、次のクエリ:
SELECT SUBSTRING_INDEX(ABC, '.', 4) FROM xxx
行が次のようなものである場合にのみ出力する必要があります (4 単語):
aaa.bbb.ccc.ddd
問題は、この行も表示されていることです。
aaa.bbb
これは、ABC に 3 つの.区切り文字があるものを返します。
select * from xxx where char_length(replace(ABC, '.', '')) + 3 = char_length(ABC)
区切り文字に複数文字の文字列がある場合は、区切り文字の長さに 3 を掛ける必要があります。