忍受着我,我是中級新手。如何決定是否應該使用CTE?
我的問題是 - 當我應該使用CTE?我如何決定是否應該使用CTE?
什麼時候應該使用這樣的:
;with cteTesting as
(
select *
from testing.first_table
)
select *
from testing.second_table s
inner join cteTesting t
on s.key = t.key
在此:
select *
from testing.second_table s
inner join
(
select *
from testing.first_table
) t
on s.key = t.key
爲什麼呢?這只是代碼流,代碼可讀性 - 還是有更多的技術?在某些情況下,會有更好的執行計劃嗎?
編輯:剛剛意識到我的示例代碼示例是非常差的。我試圖強調,在很多情況下,我可以在from語句而不是CTE中使用select,如何決定我應該使用哪一個?
非常詳細 - 謝謝你。將探索這一點,但這一切看起來像選擇CTE – Codingo 2012-07-12 07:43:31