我在一个过程中有这个查询,它正在慢慢地加载数据。是否有更快的方法来运行此查询?
SELECT date, price
FROM ( SELECT date,
price,price_src,
ROW_NUMBER() OVER (PARTITION BY date ORDER BY
CASE WHEN price_src = 'mom' THEN
0
WHEN price_src = 'dad' THEN
1
WHEN price_src = 'other' THEN
2
END) AS roworder
FROM pr.sources e
WHERE e.home = inTick
AND price IS NOT NULL
AND e.security = inVal
AND e.securityNum = NVL(inSecurity,'FWD')
AND bc= 'USD'
AND date >= NVL(startDate, date)
AND date <= NVL(endDate, date)
)
WHERE roworder = 1
ORDER BY date;
我希望获得基础货币为美元且在特定日期范围内的特定值(inval
)的定价。问题是,这里涉及优先顺序。首先尝试从“妈妈”定价来源获取它,如果没有,那么转到“爸爸”然后转到“其他”。
以下是该表的示例:
+------------+------+-----+-------------+----------+-----------+--------+ | DATE | home | bc | securityNum | security | price_src | price | +------------+------+-----+-------------+----------+-----------+--------+ | 2001-05-04 | 3A | USD | FWD | 32 | MOM | 548.54 | | 2012-05-04 | 3G | USD | BWD | 58 | DAD | 58.54 | | 2009-05-04 | 3F | USD | FWD | 39 | OTHER | 588.54 | | 2010-05-04 | 3E | USD | FWD | 38 | MOM | 38.54 | +------------+------+-----+-------------+----------+-----------+--------+
该表有超过200万条记录。它应该为特定价值(可能是货币或财产)获得特定日期的价格。
查询需要10秒才能运行(1次运行)并在循环中调用。每次执行的缓慢计时累积都会使整个事情变慢。
答案 0 :(得分:1)
如果没有进一步的信息,我会建议: