-
(root@127.0.0.1) [test]> select * from city;
-
+-----------------------------------------+
-
| name |
-
+-----------------------------------------+
-
| 北京市北京市北京北京北京市 |
-
| tom is a good tom boy |
-
+-----------------------------------------+
-
2 rows in set (0.00 sec)
查看name中tom出现的次数
(root@127.0.0.1) [test]> select (length(name)-length(replace(name,"tom","")))/length("tom") as count ,name from city;
+--------+-----------------------------------------+
| count | name |
+--------+-----------------------------------------+
| 0.0000 | 北京市北京市北京北京北京市 |
| 2.0000 | tom is a good tom boy |
+--------+-----------------------------------------+
2 rows in set (0.00 sec)