MySQL - SQL length question
What is the correct SQL statement for
SELECT kw where l开发者_开发知识库ength(kw) > 3 FROM data group by kw
You need to re-order the query and use the CHAR_LENGTH() function:
SELECT kw FROM data WHERE CHAR_LENGTH(kw) > 3 GROUP BY kw;
It should be noted that using functions in the WHERE clause is frowned upon as the function is executed for every row of the data
table.
If you are not restricted by disk space, consider re-architecting your solution so you can store the required information in another column (in this case, store the length of kw
in a kw_length
). This will speed the query up and save unnecessary processor cycles.
精彩评论