跳到主要內容 跳至補充內容

autonumber - 指令碼函數

此指令碼函數會針對在指令碼執行期間出現的每個相異的 expression 評估值,傳回唯一的整數值。此函數可用於如建立複雜金鑰的簡潔記憶表示法。

資訊備註您只能連接已在相同資料載入中產生的 autonumber 索引鍵,因為根據表格的讀取順序產生了整數。如果您需要在資料載入之間使用持續存在的索引鍵,無論來源資料排序為何,您應該使用 hash128hash160hash256 函數。

語法:  

autonumber(expression[ , AutoID])

引數:  

引數 描述
AutoID

如果 autonumber 函數在指令碼內用於不同的索引鍵,為了建立多個計數器執行個體,可使用選用參數 AutoID 來命名各個計數器。

範例: 建立複合索引鍵

在此範例中,我們使用 autonumber 函數建立複合索引鍵以節省開支。該範例僅供示範之用,在處理含大量列的表格時具有意義。

範例資料
Region Year Month Sales
North 2014 May 245
North2014May347
North2014June127
South2014June645
South2013May367
South2013May221

使用內嵌資料載入來源資料。然後,我們新增一個前置載入,從 RegionYearMonth 欄位中建立複合索引鍵。

RegionSales: LOAD *, AutoNumber(Region&Year&Month) as RYMkey; LOAD * INLINE [ Region, Year, Month, Sales North, 2014, May, 245 North, 2014, May, 347 North, 2014, June, 127 South, 2014, June, 645 South, 2013, May, 367 South, 2013, May, 221 ];

 

產生的表格如下所示:

結果表格
Region Year Month Sales RYMkey
North 2014 May 245 1
North2014May3471
North2014June1272
South2014June6453
South2013May3674
South2013May2214

在此範例中,如果您需要連結至另一個表格,則可以參照 RYMkey (對於範例 1),替代字串 'North2014May'。

現在,我們使用類似的方法載入成本來源表格。在前置載入中排除 RegionYearMonth 欄位,以避免建立合成鍵,我們已使用 autonumber 函數建立複合索引鍵,進而連結表格。

RegionCosts: LOAD Costs, AutoNumber(Region&Year&Month) as RYMkey; LOAD * INLINE [ Region, Year, Month, Costs South, 2013, May, 167 North, 2014, May, 56 North, 2014, June, 199 South, 2014, June, 64 South, 2013, May, 172 South, 2013, May, 126 ];

 

現在,我們可以將表格視覺化新增至工作表,並新增 RegionYearMonth 欄位,以及銷售額和成本的 Sum 量值。該表格將如下所示:

結果表格
Region Year Month Sum([Sales]) Sum([Costs])
Totals - - 1952 784
North2014June127199
North2014May59256
South2014June64564
South2013May588465

此頁面是否對您有幫助?

若您發現此頁面或其內容有任何問題——錯字、遺漏步驟或技術錯誤——請告知我們可以如何改善!