8 个解决方案
#1
将你的表结构贴和sql贴出来
#2
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国北京*',a.`title`)>0) AND b.`isask`=1)
UNION
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国',a.`title`)>0 AND LOCATE('北京',a.`title`)>0 AND LOCATE('*',a.`title`)>0) AND b.`isask`=1) UNION (SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国',a.`title`)>0 AND LOCATE('北京',a.`title`)>0) AND b.`isask`=1)
UNION
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('北京',a.`title`)>0 AND LOCATE('*',a.`title`)>0) AND b.`isask`=1)
UNION
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国',a.`title`)>0 OR LOCATE('北京',a.`title`)>0 OR LOCATE('*',a.`title`)>0) AND b.`isask`=1)
LIMIT 0,20
#3
phpcms_ask表: askid catid title tags reward userid username addtime endtime status flag answercount anonymity hits ischeck
phpcms_ask_posts表:pid askid isask message addtime reply rptime candidate optimal reversion userid status anonymity username
phpcms_ask_posts表:pid askid isask message addtime reply rptime candidate optimal reversion userid status anonymity username
#4
既然你不需要计算出现的次数,那么合起来不是更好
SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message`
FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid`
WHERE (a.status=3 OR a.status=5) AND b.`isask`=1 AND (LOCATE('中国',a.`title`)>0 OR LOCATE('北京',a.`title`)>0 OR LOCATE('*',a.`title`)>0)
#5
若要计算匹配度,也只需
select sign(LOCATE('中国',a.`title`))+sign(LOCATE('北京',a.`title`))+sign(LOCATE('*',a.`title`)) as 匹配数 from ...
select sign(LOCATE('中国',a.`title`))+sign(LOCATE('北京',a.`title`))+sign(LOCATE('*',a.`title`)) as 匹配数 from ...
#6
感谢版主,您的方法非常有效!!现在速度快了很多。
#7
匹配度排序该如何实现呢
#8
版主 请问:按指定的關鍵字在字段中出現的次數排序 该如何实现呢? 只在一个字段中查询
#1
将你的表结构贴和sql贴出来
#2
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国北京*',a.`title`)>0) AND b.`isask`=1)
UNION
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国',a.`title`)>0 AND LOCATE('北京',a.`title`)>0 AND LOCATE('*',a.`title`)>0) AND b.`isask`=1) UNION (SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国',a.`title`)>0 AND LOCATE('北京',a.`title`)>0) AND b.`isask`=1)
UNION
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('北京',a.`title`)>0 AND LOCATE('*',a.`title`)>0) AND b.`isask`=1)
UNION
(SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message` FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid` WHERE (a.status=3 OR a.status=5) AND (LOCATE('中国',a.`title`)>0 OR LOCATE('北京',a.`title`)>0 OR LOCATE('*',a.`title`)>0) AND b.`isask`=1)
LIMIT 0,20
#3
phpcms_ask表: askid catid title tags reward userid username addtime endtime status flag answercount anonymity hits ischeck
phpcms_ask_posts表:pid askid isask message addtime reply rptime candidate optimal reversion userid status anonymity username
phpcms_ask_posts表:pid askid isask message addtime reply rptime candidate optimal reversion userid status anonymity username
#4
既然你不需要计算出现的次数,那么合起来不是更好
SELECT a.`askid`,a.`catid`,a.`title`,a.`status`,a.`addtime`,a.`reward`,a.`answercount`,b.`message`
FROM `phpcms_ask` a LEFT JOIN `phpcms_ask_posts` b ON a.`askid`=b.`askid`
WHERE (a.status=3 OR a.status=5) AND b.`isask`=1 AND (LOCATE('中国',a.`title`)>0 OR LOCATE('北京',a.`title`)>0 OR LOCATE('*',a.`title`)>0)
#5
若要计算匹配度,也只需
select sign(LOCATE('中国',a.`title`))+sign(LOCATE('北京',a.`title`))+sign(LOCATE('*',a.`title`)) as 匹配数 from ...
select sign(LOCATE('中国',a.`title`))+sign(LOCATE('北京',a.`title`))+sign(LOCATE('*',a.`title`)) as 匹配数 from ...
#6
感谢版主,您的方法非常有效!!现在速度快了很多。
#7
匹配度排序该如何实现呢
#8
版主 请问:按指定的關鍵字在字段中出現的次數排序 该如何实现呢? 只在一个字段中查询