-1

我有以下 SQL:

SELECT tab4.IRSpot as IRSpot, tab4.IRVol AS MaxPlauShift, tab4.VegElement AS MaxPlauLoss FROM
    (SELECT tab1.IRSpot, MIN(tab1.VegaElement*Probability) AS PlausibleLoss FROM
        (SELECT IRSpot, IRVol, VegaElement 
        FROM SEL_VegaElementMatrix()) tab1
    JOIN
        (SELECT IRSpot, IRVol, Probability 
        FROM Table_Name_2) tab2
    ON tab1.IRSpot = tab2.IRSpot AND tab1.IRVol = tab2.IRVol
    GROUP BY tab1.IRSpot) tab3
JOIN
    (SELECT IRSpot, IRVol, VegaElement 
    FROM SEL_VegaElementMatrix()) tab4
ON tab3.PlausibleLoss = tab4.VegaElement AND tab3.IRSpot = tab4.IRSpot

tab3 返回一行 {2,0},而 tab4 返回许多行,其中八行包含相同的值 {2,0}。

我期待我的加入返回八行结果,因为我正在执行 JOIN 但我只返回一个结果行?

4

1 回答 1

2

将其更改为 RIGHT JOIN 以找出不匹配的内容。INNER JOIN 将仅显示在两个表中都找到匹配项的行。我怀疑这是最后一个 where/on 子句中的东西,但是如果没有看到表结构和数据,很难说。

SELECT tab4.IRSpot as IRSpot, tab4.IRVol AS MaxPlauShift, tab4.VegElement AS MaxPlauLoss FROM 
    (SELECT tab1.IRSpot, MIN(tab1.VegaElement*Probability) AS PlausibleLoss FROM 
        (SELECT IRSpot, IRVol, VegaElement  
        FROM SEL_VegaElementMatrix()) tab1 
    JOIN 
        (SELECT IRSpot, IRVol, Probability  
        FROM Table_Name_2) tab2 
    ON tab1.IRSpot = tab2.IRSpot AND tab1.IRVol = tab2.IRVol 
    GROUP BY tab1.IRSpot) tab3 
RIGHT JOIN 
    (SELECT IRSpot, IRVol, VegaElement  
    FROM SEL_VegaElementMatrix()) tab4 
ON tab3.PlausibleLoss = tab4.VegaElement AND tab3.IRSpot = tab4.IRSpot 
于 2012-05-28T15:49:30.153 回答