这是有效的ANSI SQL吗?:
SELECT 1 AS X ,2 * X AS Y ,3 * Y AS Z
因为Teradata(12)既可以做到这一点,也可以做到这一点(是的,不是很疯狂):
SELECT 3 * Y AS Z ,2 * X AS Y ,1 AS X
但是SQL Server 2005需要这样的东西:
SELECT X ,Y ,3 * Y AS Z FROM ( SELECT X ,2 * X AS Y FROM ( SELECT 1 AS X ) AS X ) AS Y
不,这不是有效的ANSI。ANSI假定立即评估所有SELECT子句项。
而且我已经在SQL 2005中将其编写为:
SELECT * FROM (SELECT 1 AS X) X CROSS APPLY (SELECT 2 * X AS Y) Y CROSS APPLY (SELECT 3 * Y AS Z) Z ;