id productId attr content 1 1 颜色 红色 2 1 长度 10厘米 3 1 宽度 20厘米 4 2 颜色 红色 4 2 长度 20厘米 我想从这个表中找出 颜色为红色,长度为10厘米,宽度为20厘米的商品的id。结果应该是 1 ,sql如下:
select productId from 如表
where (attr='颜色' and content='红色')
or (attr='长度' and content='10厘米')
or (attr='宽度' and content='20厘米')
group by productId
having count(*)=3
版权声明:本文为The_Thinnest原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。