问题
I currently have the following code
select *
FROM list
WHERE name LIKE '___'
ORDER BY name;
I am trying to get it so that it only shows names with three or more words. It only displays names with three characters I cannot seem to work out the correct syntax for this.
Any help is appreciated Thankyou
回答1:
If you assume that there are no double spaces, you can do:
WHERE name like '% % %'
To get names with three or more words.
If you can have double spaces (or other punctuation), then you are likely to want a regular expression. Something like:
WHERE name REGEXP '^[^ ]+[ ]+[^ ]+.*$'
回答2:
I do believe what you are after is
SELECT *
FROM list
WHERE name LIKE '% % %'
ORDER BY name;
回答3:
you can count number of words and then select those who are equal or greater then 3 words.
SELECT * FROM list
HAVING LENGTH(name) - LENGTH(REPLACE(name, ' ', ''))+1 >= 3
ORDER BY name
DEMO HERE
*Even if you have multi spaces it will not affect here check this
来源:https://stackoverflow.com/questions/25766281/mysql-select-values-with-more-than-three-words