0

我是 XQuery 的新手。请提出一种优化以下查询的方法。

我已经尝试过以下查询,它花费的时间比预期的要多。

Select 
A.a_name, 
I.p_type, 
SUM(P.c_n_amount) AS c_n_amount,
CASE  WHEN SUM(ABS(M_value)) = 0 THEN 0
ELSE SUM(ABS(Price) * ABS(M_value)) / SUM(ABS(M_value)) END AS 
[price],
SUM(M_value) AS m_value,SUM(N50) [-50],SUM(P50) [50]
from  position P 
INNER JOIN COUNT AS A ON P.a_id = A.a_id 
INNER JOIN I_VIEW AS I ON P.i_id = I.i_id 
inner join (
select R_C.p_id,M_value,Price,N50,P50
from(
select j.p_id,
C.value('(Result[@resultName = "m_value"]/resultValue)[1]', 'float') as M_value,
C.value('(Result[@resultName = "price"]/resultValue)[1]', 'float') as Price
from  jyothi_xml j CROSS APPLY resultkeys.nodes('/Results')  T(C) 
where r_set='POLY' and r_category ='sk')  R_Category,
(select j1.p_id,
C.value('(Result[@resultName = "rate_shock_n50"]/resultValue)[1]', 'float') as N50,
C.value('(Result[@resultName = "rate_shock_p50"]/resultValue)[1]', 'float') as P50
from jyothi_xml j1 CROSS APPLY resultkeys.nodes('/Results')  T(C)
where result_set='POLY' and result_category ='rate_shocks')  R_S_Category,position p
where p.p_id=R_Category.p_id and p.p_id=R_S_Category.p_id) XMlData  on p.p_id=XMlData.p_id
WHERE P.as_of_date = '2012-10-10' 
GROUP BY A.a_name, I.p_type
4

1 回答 1

0

如果您有很多 XML 要解析,那么首先限制您需要哪些 XML 行,然后解析它们是非常有益的。因此,如果可以,请从 Position、Count 和 I_View 表中找出您需要的内容,然后在 jyothi_xml 表中搜索这些 ID。我发现这对我的查询有很大帮助。

于 2013-01-08T18:43:36.943 回答