我有一个sql script
与它one table
一起使用two alias
并在其上制作的JOIN
,但我需要了解为什么以及何时需要这样做,请详细说明?
SELECT
ISNULL(MarketValue,0)
FROM
(
SELECT TOP 5
Delta,
MarketValue
FROM
(
SELECT DISTINCT
FormatNumber(SUM([CURRENT].MarkToMarket), 0, ',', 0) AS Delta,
AVG([CURRENT].Mark) * SUM([CURRENT].Position) AS NumericPosition,
FormatNumber(AVG([CURRENT].Mark) * SUM([CURRENT].Position)* CASE WHEN [CURRENT].SecurityType IN ('Equity','Equity Option') THEN 100 ELSE 1 END, 0, ',', NULL) AS MarketValue
FROM
NAV [CURRENT]
LEFT JOIN
NAV Compare ON
[CURRENT].PurchaseLotId = Compare.PurchaseLotId AND
Compare.Date = '2012-06-06'
WHERE
[CURRENT].SecurityType not in ('Equity')
GROUP BY
ORDER BY
NumericDelta DESC
) Movers
FOR XML PATH ('TR'), TYPE
) AS VARCHAR(MAX)
)
Why it is used like FROM
NAV [CURRENT]
LEFT JOIN
NAV Compare ON
[CURRENT].PurchaseLotId = Compare.PurchaseLotId AND
Compare.Date = '2012-06-06'
NAV 只是一张表,那么取同一张表 NAV [CURRENT] 和 NAV 比较并使用 LEFT JOIN 的两个别名的目的是什么?
请详细说明。