如表: id 商品id 商品属性 属性内容
id productId attr content
1 1 颜色 红色
2 1 长度 10厘米
3 1 宽度 20厘米
4 2 颜色 红色
4 2 长度 20厘米
我就想从这个表中找出 颜色为红色,长度为10厘米 的商品的id 结果应该是 1
请问各位查询语句怎么写呢? 在线等!
id productId attr content
1 1 颜色 红色
2 1 长度 10厘米
3 1 宽度 20厘米
4 2 颜色 红色
4 2 长度 20厘米
我就想从这个表中找出 颜色为红色,长度为10厘米 的商品的id 结果应该是 1
请问各位查询语句怎么写呢? 在线等!
解决方案 »
- 求一个sql语句
- 联合查询时,a.a=b.a AND a.a=c.a 和 a.a=b.a=c.a有神马区别啊?
- 请问怎样建商品表?
- mysql经常卡死是什么问题?
- MYSQL:alter table 表名 add primary key(列名) 这个语句执行后无法设定主键
- 关于MySQLQueryBrowser中输入中文后查询显示乱码的问题!
- SQL server 和 MySQL有什么不同?
- **关于mysql的日志**
- 低版本的MYSQL导出的库文件到入到高版本的数据库出现问题!(请高手帮我看看这些出错提示是什么)
- 问个初学问题?-------------->>>>>>>>>>>>>>>>>>>>>>>>
- mysql 子查询 having为空问题
- mysql启动错误信息
from attr='红色' and attr='10厘米'
group by productId
from 如表 a , 如表 b
where a.productId=b.productId
and a.attr='颜色' and a.content='红色'
and b.attr='长度' and b.content='10厘米'
from tb
where attr='颜色' and content='红色'
and attr='长度' and content='10厘米'
group by productId
having (distinct attr)>1
from tb
where (attr='颜色' and content='红色')
or (attr='长度' and content='10厘米')
group by productId
having (distinct attr)>1
from tb
where (attr='颜色' and content='红色')
or (attr='长度' and content='10厘米')
group by productId
having (count(*))>1
from 如表 a
where exists (select 1 from 如表 where productId=a.productId and attr='颜色' and content='红色')
and exists (select 1 from 如表 where productId=a.productId and attr='长度' and content='10厘米')
and exists (select 1 from 如表 where productId=a.productId and attr='宽度' and content='20厘米')
from 如表
where (attr='颜色' and content='红色')
or (attr='长度' and content='10厘米')
or (attr='宽度' and content='20厘米')
group by productId
having count(*)=3