我正在使用 SQL Server 2008。
我有一个名为 testView 的视图
在视图中,其中一列正在使用从该页面获取的另一个查询 - http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/
即沿着这种格式
Create View testView as
SELECT p1.CategoryId,
( SELECT ProductName + ','
FROM Northwind.dbo.Products p2
WHERE p2.CategoryId = p1.CategoryId
ORDER BY ProductName
FOR XML PATH('') ) AS Products
FROM Northwind.dbo.Products p1
运行以下查询时,如果视图中有 60,000 行,大约需要 110 秒。
select * from testView where Products like '%asdf%'
可以提供哪些建议来改进此查询?