继续求一SQL语句
现有表结构如下
T_Sell_Property
字段1 SellID
字段2 ValueString
字段3 LabelID
我希望查询出 ValueString= 'a ' AND labelID=1,ValueString= 'b ' AND LabelID=2
并且SellID要相等。
效率越高越好拉。
------解决方案--------------------select *
from T_Sell_Property t
where (select count(1) from T_Sell_Property where SellID=t.SellID and (ValueString= 'a ' AND labelID=1 or ValueString= 'b ' AND LabelID=2))> 1
------解决方案--------------------select a.SellID,a.ValueString,a.LabelID
(select * from T_Sell_property
where ValueString= 'a ' and labelID=1) a,
(select * from T_Sell_property
where ValueString= 'b ' and labelID=2) b
where a.SellID=b.SellID
union all
select b.SellID,b.ValueString,b.LabelID
(select * from T_Sell_property
where ValueString= 'a ' and labelID=1) a,
(select * from T_Sell_property
where ValueString= 'b ' and labelID=2) b
where a.SellID=b.SellID