mysqlselect怎么写?

How to write mysql select?

我有一个 table 存储与产品关联的属性值。

row_id  product_id attribute_id  value
1   1   1   a
2   1   2   b
3   2   1   d
4   2   2   e

我如何编写 select 来获取 attribute_id=2 的值,仅针对具有 attribute_id=1 的值="a" 的产品?

谢谢,

祝你有愉快的一天

也许这就是你想要的?

select * 
from your_table
where attribute_id = 2 
  and product_id in (
    select product_id 
    from your_table
    where attribute_id = 1 and value = 'a'
)

对于您的示例数据,将返回带有 row_id = 2 的行。