select comid
from tb
where attName in ('品牌','价格','类型') and (attValue in ('诺基亚','直板') or (attValue between 1000 and 2000))
group by comId
having count(*)=6
[/Quote]
是不是应该是having count(*)=3
select * from commodity
where exists (select 1 from attribute where comId=commodity.comId and attName='品牌' and attValue='诺基亚')
and exists (select 1 from attribute where comId=commodity.comId and attName='价格范围' and attValue between 1000 and 2000)
and exists (select 1 from attribute where comId=commodity.comId and attName='类型' and attValue='直板')
select comid
from tb
where attName in ('品牌','价格','类型') and (attValue in ('诺基亚','直板') or (attValue between 1000 and 2000))
group by comId
having count(*)=6