我使用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
当下面的查询运行时,它正在约110秒的时候有60,000视图中的行。
select * from testView where Products like '%asdf%'
可以提供哪些建议来改进此查询?
沿着'GROUP BY p1.CategoryId'的行,可能吗? –