它只是我在SQL中的启动,我有4.5 GB的数据库,我试图从特定日期选择记录并执行25秒。有没有办法让它更快?
我的查询:
select a.*,b.ModelName
from Validation a
left Join ModelMaster b
on SUBSTRING(a.STB,11,2) = b.ProductCode and
Convert(int,substring(a.STB,9,2)) = b.BrandCode
Where STB in (Select STB From Scan_Data_For_Century) and
a.date between '2015-01-14' and '2015-01-14'
答案 0 :(得分:0)
您可以尝试这样的查询:
SELECT a.*,
b.ModelName
FROM Scan_Data_For_Century sd
INNER JOIN Validation a
ON a.STB = sd.STB AND a.date between '2015-01-14' and '2015-01-14'
LEFT JOIN ModelMaster b
ON SUBSTRING(a.STB,11,2) = b.ProductCode AND Convert(int,substring(a.STB,9,2)) = b.BrandCode
我知道,那一定是评论。请尝试查询。如果它不会帮助我将删除我的答案。
答案 1 :(得分:0)
试试这个:
;with cte as (
select
*,
ProductCode = SUBSTRING( STB, 11, 2 ),
BrandCode = Convert( int, substring( STB, 9, 2 ) )
from Validation
)
select
a.*,
c.ModelName
from
cte a
inner join Scan_Data_For_Century b on ( b.STB = a.STB )
left Join ModelMaster c on ( c.ProductCode = b.ProductCode ) and ( c.BrandCode = b.BrandCode )
Where
( a.date = '2015-01-14' )
还索引:
可能有帮助