mysql根据相关匹配度推荐结果

项目要求:

1. 优先匹配胖瘦、身高、风格全部一致的

2. 如果没有找到或内容出完,匹配胖瘦和身高一致的

3. 如果没有找到或内容出完,匹配胖瘦一致的

4. 如果没有找到或内容出完,匹配任意条件一致的

5 .如果没有找到或内容出完,不再推送数据

sql写法:

SELECT
	user_id,
	user_icon,
	user_name,
	user_level,
	introduce,
	att_count,
	image_info_list,
	(
		SELECT
			COUNT(*)
		FROM
			app_user_attention
		WHERE
			user_id =23026
		AND att_id = main_page_daren.user_id
	) AS user_att,
	'daren' AS type,
	case body_high
	when body_high = '高挑' then 1
	else 0
	end as high_flg,
	case body_fat
	when body_fat = '骨干' then 1
	else 0
	end as fat_flg,
	case 
	when style LIKE '%休闲风%' then 1
	when  style LIKE '%浪漫风%' then 1
	when style LIKE '%潮酷风%' then 1
	when style LIKE '%甜美风%' then 1
	when style LIKE '%文艺风%' then 1
	else 0
	end as style_flg
FROM
	`main_page_daren`
WHERE
	1 <> 1
OR body_high = '高挑'
OR body_fat = '骨干'
OR age = '学生党'
OR (
	style LIKE '%休闲风%'
	OR style LIKE '%浪漫风%'
	OR style LIKE '%潮酷风%'
	OR style LIKE '%甜美风%'
	OR style LIKE '%文艺风%'
)
AND sex = '女'
ORDER BY
	fat_flg desc,
	high_flg desc,
	style_flg desc,
	sort DESC

 SQL数据见附件。

猜你喜欢

转载自sky-xin.iteye.com/blog/2281954