我使用Microsoft SQL Server。必要性,這種情況
我經常遇到這樣的代碼:
select (a*5 + a*4 + a*3) as a1 --some complicated and very long manipulation of column 'a'
into #Temp1
from Table1
select a1, case when a1 > 5 then 1 else 0 end as myResult
from #Temp1
我曾嘗試使用:
select (a*5 + a*4 + a*3) as a1, case when a1 > 5 then 1 else 0 end as myResult
from Table1
,並提示錯誤爲 'A1' 無效的列名。我明白這一點,但對於像我這樣的情況是有辦法避免創建#TEMP1一步?
編輯: 我知道這樣的編碼結構爲:
select (a*5 + a*4 + a*3) as a1, case when (a*5 + a*4 + a*3) > 5 then 1 else 0 end as myResult
from Table1
有關列一個非常令人費解的操作「A」的代碼變得不可讀。
a1是一個alisas,只要sql server知道沒有a1,alisase的行爲更像是標籤而不是實際的列 – Phil3992