with as内的表能不能用临时表?。
例如
WITH t AS(
SELECT
b.year
,b.month
,a.qty-b.qty AS qty
FROM
(SELECT qty FROM a WHERE month=1 AND year=2013) AS a
,b as b
WHERE NOT EXISTS(SELECT 1 FROM b AS x
WHERE x.month>b.month
AND x.year=2012
)
UNION ALL
SELECT
b.year
,b.month
,t.qty-b.qty
FROM
b
,t
WHERE b.year=t.year
AND b.month=t.month-1
)
select * from t
中的a,b两个表都是临时表,,2005sql
例如
WITH t AS(
SELECT
b.year
,b.month
,a.qty-b.qty AS qty
FROM
(SELECT qty FROM a WHERE month=1 AND year=2013) AS a
,b as b
WHERE NOT EXISTS(SELECT 1 FROM b AS x
WHERE x.month>b.month
AND x.year=2012
)
UNION ALL
SELECT
b.year
,b.month
,t.qty-b.qty
FROM
b
,t
WHERE b.year=t.year
AND b.month=t.month-1
)
select * from t
中的a,b两个表都是临时表,,2005sql
with as 唯一的限制是 前面的 CET 不能引用后面的 CET
http://msdn.microsoft.com/zh-cn/library/ms175972(v=sql.100).aspx