我的应用程序需要从 SQL Server 数据库中获取数据。我的问题是必须将 3 个表连接到一个视图中。这需要很长时间(生成视图大约需要 30 秒)所以我想知道是否有办法优化这个 SQL 查询?
SQL查询:
SELECT TOP (100) PERCENT Request1.RequestID,
TrackIT.dbo.Sending.Barcode,
TrackIT.dbo.Address_View.AdrID,
TrackIT.dbo.Address_View.Name,
TrackIT.dbo.Address_View.Street,
TrackIT.dbo.Address_View.HouseNo,
TrackIT.dbo.Address_View.Postal,
TrackIT.dbo.Address_View.City,
TrackIT.dbo.Address_View.Country,
Request1.Latitude,
Request1.Longitude,
Request1.ReceivedDate
FROM (SELECT DISTINCT RequestID,
Ltrim([Content]) AS Barcode,
Latitude,
Longitude,
ReceivedDate
FROM RequestWithLocation
WHERE ( Site LIKE '%Z' )
AND ( [Content] <> '' )
AND ( AddressID = '0' )
AND ReceivedDate > Dateadd(day, -7, Getdate())) AS Request1
INNER JOIN TrackIT.dbo.Sending
ON Request1.Barcode = TrackIT.dbo.Sending.Barcode
INNER JOIN TrackIT.dbo.Address_View
ON TrackIT.dbo.Sending.DeliveryAdrID = TrackIT.dbo.Address_View.AdrID
ORDER BY AdrID
任何人都可以帮忙吗?