数据库tag字段内容格式:a,b,c,d ...
假设有这几条记录
1:刘世允
2:郑胜浩
3:申东烨
4: 申东烨,郑胜浩,刘世允,安英美
5: 郑胜浩,刘世允,安英美
6: 申东烨,郑胜浩
7:刘世允,安英美
给出的查询tag
$tag = '申东烨,郑胜浩,刘世允,安英美,李尚勋';
按照相同词的个数排序
查询的结果
1: 申东烨,郑胜浩,刘世允,安英美
2: 郑胜浩,刘世允,安英美
3: 申东烨,郑胜浩
4:刘世允,安英美
5:刘世允
6:郑胜浩
7:申东烨
数据库tag字段内容格式:a,b,c,d ...
假设有这几条记录
1:刘世允
2:郑胜浩
3:申东烨
4: 申东烨,郑胜浩,刘世允,安英美
5: 郑胜浩,刘世允,安英美
6: 申东烨,郑胜浩
7:刘世允,安英美
给出的查询tag
$tag = '申东烨,郑胜浩,刘世允,安英美,李尚勋';
按照相同词的个数排序
查询的结果
1: 申东烨,郑胜浩,刘世允,安英美
2: 郑胜浩,刘世允,安英美
3: 申东烨,郑胜浩
4:刘世允,安英美
5:刘世允
6:郑胜浩
7:申东烨
----------------建表
1 2 3 |
|
```sql
mysql> describe testsort
-> ;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| tag | varchar(100) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
1 row in set (0.07 sec)
1 2 3 4 5 6 7 8 9 10 11 12 |
|
----------------方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
----------------另外注意
Responses below will get you there. However, don't forget to use CHAR_LENGTH() instead of LENGTH() if you're using multibyte characters. – inhan Sep 10 '12 at 3:03
http://stackoverflow.com/questions/12344795/count-the-number-of-occurences-of-a-string-in-a-varchar-field