-2
我有一個工作查詢,如下圖所示:與組優化SQL查詢通過和彙總
SELECT TOP 1000
c.B,
c.N,
c.V,
c.T,
SIS = stuff((
SELECT ', ' + si.S
FROM
COMP com
JOIN CCA cca ON com.Cid = cca.CId
JOIN CC cc ON cca.Cid = cc.Cid
JOIN SI si ON si.SId = cc.SId
WHERE
com.N=c.N
FOR XML PATH('')), 1, 2, ''
)
FROM
COMP c
JOIN CCA cca ON c.Cid = cca.CId
JOIN CC cc ON cca.Cid = cc.Cid
JOIN SI si ON si.SId = cc.SId
where c.N like '%searchstring%'
and si.Sin like '%searchstring%'
group by c.B, c.N, c.V, c.T
order by c.N desc;
它提供了正確的結果。我正在做東西()以獲得逗號分隔的聚合。查詢很慢。想知道是否有辦法優化它?
我想'FOR XML PATH'會讓你的查詢速度變慢,如果有可能改變你的方式;)。 –
與WHERE的LIKE比較,查詢速度也慢 – Fabio