1
我可以在一個查詢中使用多個WITH子查詢嗎?多個子查詢
;WITH x AS (
SELECT ...
),
WITH y AS (
SELECT ...
)
SELECT * FROM z
INNER JOIN x ON ...
INNER JOIN y ON ...
我可以在一個查詢中使用多個WITH子查詢嗎?多個子查詢
;WITH x AS (
SELECT ...
),
WITH y AS (
SELECT ...
)
SELECT * FROM z
INNER JOIN x ON ...
INNER JOIN y ON ...
這就是所謂的common table expression,是的,你可以使用多個CTE的,只用一個WITH
並刪除第二with
這樣的:
WITH x AS (
SELECT ...
),y AS (
SELECT ...
)
SELECT * FROM z
INNER JOIN x ON ...
INNER JOIN y ON ...
太好了!我無法找到任何在互聯網上的好例子:(搜索keyworh''是不是非常有用:( –
@TomasWalek正確的術語使用應該是** SQL Server多個CTE **,看到這個例子:http ://blog.sqlauthority.com/2009/08/08/sql-server-multiple-cte-in-one-select-statement-query/ –
@TomasWalek同樣這本書:[** Microsoft SQL Server 2012 T-SQL基礎知識**](http://www.amazon.com/Microsoft-Server-2012-T-SQL-Fundamentals/dp/0735658145)是一本關於sql server基礎知識的好書。 –