SELECT [SellID]
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] where title like '%测%'
and SellID IN (SELECT SellID FROM [T_Sell_Property] where ValueString='黑色' AND LabelID=2)一直说IN 效率不高, 可我现在有这样的需求,应该怎样优化呢?
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] where title like '%测%'
and SellID IN (SELECT SellID FROM [T_Sell_Property] where ValueString='黑色' AND LabelID=2)一直说IN 效率不高, 可我现在有这样的需求,应该怎样优化呢?
(
SELECT [SellID]
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] where title like '%测%'
) a,
(
SELECT SellID FROM [T_Sell_Property] where ValueString='黑色' AND LabelID=2
) b
where a.SellID = b.SellID
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] a join [T_Sell_Property] b
on a.title like '%测%' and b.ValueString='黑色' and b.LabelID=2 and a.SellID = b.SellID
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] a where title like '%测%'
and SellID exists (SELECT * FROM [T_Sell_Property] where a.sellid=sellid and ValueString='黑色' AND LabelID=2)
SELECT [SellID]
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] a where title like '%测%'
and exists (SELECT * FROM [T_Sell_Property] where a.sellid=sellid and ValueString='黑色' AND LabelID=2)
,T.[SortID]
,T.[Title]
FROM [TestSort].[dbo].[T_Sell] AS T
INNER JOIN (SELECT SellID FROM [T_Sell_Property] where ValueString='黑色' AND LabelID=2) AS P
ON T.SellID=P.SellID WHERE T.title like '%测%'
大家看看我这个是不是效率会高点?
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] a,(SELECT SellID FROM [T_Sell_Property] where ValueString='黑色' AND LabelID=2) b
where title like '%测%'
and a.SellID=b.SellID
,[SortID]
,[Title]
FROM [TestSort].[dbo].[T_Sell] a where title like '%测%'
and exists(SELECT 1 FROM [T_Sell_Property] where ValueString='黑色' AND LabelID=2
and a.SellID=SellID)