- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为用户可以查询的食谱网站做一个高级搜索功能;
上述几点可以在用户查询中结合在一起。
我已经完成了一半,我可以查询包含指定成分并在一定时间内烹制的食谱。
这是我的数据库结构;
表:食谱
食谱 ID、食谱名称、 cooking 时间
表:成分
成分_ID,成分_名称
表:Recipe_Ingredients
Recipe_Ingredient_ID, Ingredient_ID, Recipe_ID
到目前为止,这是我的 SQL 查询;
SELECT count(*) as rowcount, r.Recipe_name
FROM Recipes AS r
INNER JOIN Recipe_Ingredients AS ri
ON r.Recipe_ID = ri.Recipe_ID
INNER JOIN Ingredients AS i
ON ri.Ingredient_ID = i.Ingredient_ID
AND i.Ingredient_Name IN ('penne','onion')
AND r.Cooking_time < 60
GROUP BY r.Recipe_name HAVING rowcount = 2;
他们将获得包含“通心粉”和“洋葱”的食谱,并在 60 分钟内完成 cooking 。
我想不通的是如何按照以下方式查询食谱;
我试过下面的代码,但它不起作用;
SELECT count(*) as rowcount, r.Recipe_name
FROM Recipes AS r
INNER JOIN Recipe_Ingredients AS ri
ON r.Recipe_ID = ri.Recipe_ID
INNER JOIN Ingredients AS i
ON ri.Ingredient_ID = i.Ingredient_ID
AND i.Ingredient_Name IN ('penne','onion')
AND i.Ingredient_Name NOT IN ('butter')
AND r.Cooking_time < 60
GROUP BY r.Recipe_name HAVING rowcount = 2;
非常感谢任何帮助!
谢谢。
最佳答案
你可以使用
SELECT r.Recipe_name,
r.Recipe_ID
FROM Recipes AS r
INNER JOIN Recipe_Ingredients AS ri
ON r.Recipe_ID = ri.Recipe_ID
INNER JOIN Ingredients AS i
ON ri.Ingredient_ID = i.Ingredient_ID
WHERE i.Ingredient_Name IN ( 'penne', 'onion', 'butter' )
AND r.Cooking_time < 60
GROUP BY r.Recipe_ID, /*<-- In case two recipes with same name*/
r.Recipe_name
HAVING
/*Must contain both these*/
COUNT(DISTINCT CASE
WHEN i.Ingredient_Name IN ( 'penne', 'onion' ) THEN i.Ingredient_Name
END) = 2
AND
/*Can't contain these*/
MAX(CASE
WHEN i.Ingredient_Name IN ( 'butter' ) THEN 1
ELSE 0
END) = 0
关于mysql - SQL 查询具有这些成分的食谱)但不是这些成分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28009961/
我有一些带有反应组件抽象的外部 UI,我想从试剂中重用它们,有没有什么方法可以通过从 clojurescript 传递数据来直接渲染预定义的 react 组件。我是 clojurescript 初学者
我刚刚构建了一个库(Material Components库)from source并将本地Maven存储库添加到了我的项目中。现在,我可以通过将Log调用添加到库的本地源中来成功地进行一些外行调试。
我正在尝试测试呈现 grommet 的组件菜单 组件。索环 Menu 组件将绝对定位的菜单呈现到文档的顶层,作为子级插入到 body 中。因此它呈现在包装器的范围之外。我可以使用 document.b
如何创建一个凹形的 SKPhysicsBody? 我的猜测是创建一个由多个凸体组成的复合节点。我可以用任何其他方式“粘贴”它们,从而在它们之间创建 SKPhysicsJointFixed 吗? 最佳答
我正在开发一个食谱应用程序来帮助我妻子培养她的蛋糕爱好。这个想法是创建一个食谱数据库来保存她所有的蛋糕食谱。 每个食谱都有多种成分。每种成分都会有测量值(克、毫升、茶匙等),然后是数量。 我了解如何创
我正在使用 sklearn's PCA用于对大量图像进行降维。安装 PCA 后,我想看看组件的外观。 可以通过查看 components_ 属性来做到这一点。没有意识到这是可用的,我做了其他事情: e
我是一名优秀的程序员,十分优秀!