更新时间:2023-11-15 16:08:46
考虑:
select *
from tab1
where char_length(type) - char_length(replace(type, ',', '')) + 1 = qta
表达式char_length(type) - char_length(replace(type, ',', ''))
为您提供字符串中的逗号数.在其中添加1
可以得到字符串中的单词数.
Expression char_length(type) - char_length(replace(type, ',', ''))
gives you the number of commas in the string. Adding 1
to that gives you the number of words in the string.
Demo on DB Fiddle:
id | cod | type | qta
-: | :-- | :---------- | --:
1 | aaa | aaa,bbb,ccc | 3
2 | aaa | ddd | 1
4 | aaa | ggg,hhh | 2