我有ingredient
。ingredientId
是709,710,711这个ID我被放入成分子查询中AS match_percentage
我怀疑(3*100 / count
正在计算ingredient
。ingredientId
,这些都来自我的PHP代码,我给出了我的解决方案的示例。
现在结果就像那些RECIPE_ID
我传递了三个ingredient
。ingredientId
与此表recipe_ingredient
匹配。ingredientId
并保持recipe_ingredient
}。recipeId
我想要RECIPE_ID
|结果为1和3。只有世界卫生组织有三个ID 709,710,711甚至不是两个709,710。
这是我的RECIPE_ID
查询:
SELECT
`recipe`.`recipeId` AS recipe_id ,
(select count(`recipe_ingredient`.ingredientId) from `recipe_ingredient` where `recipe`.recipeId = `recipe_ingredient`.recipeId) as ingredientCount ,
IF(
(select (3*100 / count(DISTINCT `recipe_ingredient`.ingredientId)) from `recipe_ingredient` where `recipe_ingredient`.recipeId = `recipe`.recipeId)>99
,100
,round( (select (3*100 / count(DISTINCT `recipe_ingredient`.ingredientId)) from `recipe_ingredient` where `recipe_ingredient`.recipeId = `recipe`.recipeId) )
)
as match_percentage ,
GROUP_CONCAT(
DISTINCT `recipe_ingredient`.ingredientId
ORDER BY `recipe_ingredient`.ingredientId ASC
) as recipeIngredients
from `recipe`
left join `recipe_ingredient` on `recipe_ingredient`.recipeId = `recipe`.recipeId
left join `ingredient` on `ingredient`.ingredientId = `recipe_ingredient`.ingredientId
where `recipe`.`recipeId` IN(
SELECT
`recipe_ingredient`.`recipeId`
FROM `recipe_ingredient`
WHERE `recipe_ingredient`.`ingredientId`
IN(
SELECT `ingredient`.`ingredientId` AS linkIng
FROM `ingredient`
WHERE `ingredient`.`ingredientId` IN(709,710,711) or `ingredient`.`linkIngredientPerent` IN(709,710,711)
)
GROUP BY `recipe_ingredient`.`recipeId`
ORDER BY `recipe_ingredient`.`recipeId` ASC
)
and (select (3*100 / count(DISTINCT `recipe_ingredient`.ingredientId)) from `recipe_ingredient` where `recipe_ingredient`.recipeId = `recipe`.recipeId) > 24
group by `recipe`.recipeId