2012-05-14 286 views
0

我需要计算搜索关键字在搜索字段中的重复次数。通过mysql查询搜索关键字的搜索关键字来计算搜索关键字

举例来说,如果我有表wp_posts这样

ID  post _content  post_title 
----------------------------------------------- 
    1  page page page  page 
    2  page test   page 
    3  page foo   test 

我想结果一样,如果任何一个搜索页面

ID total count 
1 4 
1 2 
2 1 
+0

所以你有两张桌子还是只有一张......?或在哪里存储访问计数? – Addicted

回答

1

试试这个

SELECT id , 
       FLOOR(((length(REPLACE(post_content, '', '')) 
         - length(REPLACE(REPLACE(post_content, ' ', ''), 
             'page', ''))))/length('page')) 
       + FLOOR(((length(REPLACE(post_title, ' ', '')) 
          - length(REPLACE(REPLACE(post_title, ' 
', ''), 'page', ''))))/length('page')) "count of 'page'" 
     FROM page_search ; 
+0

这似乎工作.. – Obhaso