mysql中多个签入同一列

czfnxgou  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(447)

我有一张table如下:

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

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'))

返回模型ID 8, 9 . 但似乎我不能在同一个字段中设置多个条件。
我也试过解决办法,在这篇帖子里还是没什么!我怎样才能得到这个结果?我用的方法 AND 子句不正确,但类似于我要在查询中实现的逻辑。

2cmtqfgy

2cmtqfgy1#

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

制造 andor 就像上面我想的那样 and 逻辑上是错误的

cwxwcias

cwxwcias2#

您要求的行的属性是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')

相关问题