Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

從查詢傳回之結果集的第一筆或最後一筆記錄傳回域值。

語法

第一個 ( 表示 式)

上次 ( )

expr 佔位元代表 字串運算式 識別包含您要使用之數據的欄位,或使用該欄位中的數據執行計算的運算式。 expr 中的操作數可以包含數據表字段的名稱、常數或函數 (可以是固有的或使用者定義的,但不能包含其中一個其他 SQL 匯總函數) 。

註解

這些函數會分別傳回查詢傳回之結果集的第一筆或最後一筆記錄中指定欄位的值。 如果查詢不包含 ORDER BY 子句,這些函數傳回的值將會任意傳回,因為記錄通常不會以特定順序傳回。

範例

Expression

結果​​

SELECT First (DateofSale) AS Expr1 FROM ProductSales;

傳回 ProductSales 數據表中 「DateofSale」 欄位的第一個值。

SELECT Last (UnitPrice) as LastPrice, First (DateofSale) AS FirstDate FROM ProductSales;

傳回 “UnitPrice” 欄位的 [最後一個] 值,以及 “DateofSale” 字段中的第一個值,分別顯示在 [LastPrice] 和 [FirstDate] 欄中。

計算 SQL 函數中的欄位

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×