gpt4 book ai didi

mysql - Mysql中同一列的多次检查

转载 作者:行者123 更新时间:2023-11-29 05:57:17 24 4
gpt4 key购买 nike

我有如下表格:

enter image description here

在这里,我想运行一个如下所示的查询:

SELECT model_id 
FROM model_attributes
WHERE ((attributes_id=2 and attributes_value='32mb')) AND ((attributes_id=4 AND attributes_value='5.00 inch') OR (attributes_id=4 and attributes_value='6.00 inch')) AND ((attributes_id=5 and attributes_value='here') OR (attributes_id=5 and attributes_value='asfdsdf'))

返回 model_ids 8, 9。但似乎我不能在同一个字段中放置多个条件。

我还尝试了 this 中的解决方案仍然没有发布!我怎样才能得到这个结果?我使用 AND 子句的方式不正确,但类似于我想在查询中实现的逻辑。

最佳答案

您要查询 attributes_id 为 2、4 和 5 的行,这永远不会是真的。

试试这个:

WHERE (attributes_id=2 AND attributes_value='32mb') OR 
(attributes_id=4 AND attributes_value in ('5.00 inch', '6.00 inch') OR
(attributes_id=5 AND attributes_valuein ('here', 'asfdsdf')

关于mysql - Mysql中同一列的多次检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48280237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com