------解决方案--------------------
SET @a1='微胖'; SET @a2='北京'; SET @a3='高中'; SET @a4='1000-3000'; SET @a5='不限'; SET @a6='不限'; SET @a7='不限'; SET @a8='游泳'; SELECT *,ROUND(ss/8,2) FROM ( SELECT *, IF(INSTR(bodytype,@a1)>0 OR @a1='不限',1,0)+ IF(INSTR(address,@a2 )>0 OR @a2='不限',1,0)+ IF(INSTR(bankgroued,@a3)>0 OR @a3='不限',1,0)+ IF(income BETWEEN 0+LEFT(@a4,INSTR(@a4,'-')-1) AND RIGHT(@a4,LENGTH(@a4)-INSTR(@a4,'-')) OR @a4='不限',1,0)+ IF(INSTR(housing,@a5)>0 OR @a5='不限',1,0)+ IF(INSTR(car,@a6)>0 OR @a6='不限',1,0)+ IF(INSTR(vocation,@a7)>0 OR @a7='不限',1,0)+ IF(INSTR(hobby,@a8)>0 OR @a8='不限',1,0) AS ss
FROM `app_makinginfo`) aa
------解决方案-------------------- SET @a1='微胖'; SET @a2='北京'; SET @a3='高中'; SET @a4='1000-3000'; SET @a5='不限'; SET @a6='不限'; SET @a7='不限'; SET @a8='游泳'; SELECT *,ROUND(ss/8,2) AS 配对率 FROM ( SELECT *,LENGTH(@a4)-INSTR(@a4,'-'),RIGHT(@a4,LENGTH(@a4)-INSTR(@a4,'-')), IF(INSTR(bodytype,@a1)>0 OR @a1='不限',1,0)+ IF(INSTR(address,@a2 )>0 OR @a2='不限',1,0)+ IF(INSTR(bankgroued,@a3)>0 OR @a3='不限',1,0)+ IF(income BETWEEN 0+LEFT(@a4,INSTR(@a4,'-')-1) AND RIGHT(@a4,LENGTH(@a4)-INSTR(@a4,'-')) OR @a4='不限',1,0)+ IF(INSTR(housing,@a5)>0 OR @a5='不限',1,0)+ IF(INSTR(car,@a6)>0 OR @a6='不限',1,0)+ IF(INSTR(vocation,@a7)>0 OR @a7='不限',1,0)+ IF(INSTR(hobby,@a8)>0 OR @a8='不限',1,0) AS ss
FROM `app_makinginfo`) aa ORDER BY 配对率 DESC
------解决方案--------------------
浪费时间!你所谓的测试数据自己试过吗?!