指令碼範例
在此範例中,首先以不含 AutoNumber 陳述式的方式載入資料。然後再新增 AutoNumber 陳述式以顯示效果。
範例中使用的資料
在資料載入編輯器中載入下列資料作為內嵌載入,以建立以下的指令碼範例。目前先忽略已註解的 AutoNumber 陳述式。
RegionSales:
LOAD *,
Region &'|'& Year &'|'& Month as KeyToOtherTable
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
];
Budget:
LOAD Budget,
Region &'|'& Year &'|'& Month as KeyToOtherTable
INLINE
[Region, Year, Month, Budget
North, 2014, May, 200
North, 2014, May, 350
North, 2014, June, 150
South, 2014, June, 500
South, 2013, May, 300
South, 2013, May, 200
];
//AutoNumber KeyToOtherTable;
如需更多關於使用內嵌載入的資訊,請參閱 內嵌載入。
建立視覺化
在 Qlik Sense 工作表中建立兩個表格視覺化。將 KeyToOtherTable、Region、Year、Month 和 Sales 作為維度新增至第一個表格。將 KeyToOtherTable、Region、Year、Month 和 Budget 作為維度新增至第二個表格。
結果
RegionSales 表格
KeyToOtherTable |
Region |
Year |
Month |
Sales |
North|2014|June |
North |
2014 |
June |
127 |
North|2014|May | North | 2014 | May | 245 |
North|2014|May | North | 2014 | May | 347 |
South|2013|May | South | 2013 | May | 221 |
South|2013|May | South | 2013 | May | 367 |
South|2014|June | South | 2014 | June | 645 |
Budget 表格
KeyToOtherTable |
Region |
Year |
Month |
Budget |
North|2014|June |
North |
2014 |
June |
150 |
North|2014|May | North | 2014 | May | 200 |
North|2014|May | North | 2014 | May | 350 |
South|2013|May | South | 2013 | May | 200 |
South|2013|May | South | 2013 | May | 300 |
South|2014|June | South | 2014 | June | 500 |
解釋
範例顯示連結兩個表格的複合欄位 KeyToOtherTable。未使用 AutoNumber。注意 KeyToOtherTable 值的長度。
新增 AutoNumber 陳述式
在載入指令碼中取消註解 AutoNumber 陳述式:
AutoNumber KeyToOtherTable;
結果
RegionSales 表格
KeyToOtherTable |
Region |
Year |
Month |
Sales |
1 |
North |
2014 |
June |
127 |
1 | North | 2014 | May | 245 |
2 | North | 2014 | May | 347 |
3 | South | 2013 | May | 221 |
4 | South | 2013 | May | 367 |
4 | South | 2014 | June | 645 |
Budget 表格
KeyToOtherTable |
Region |
Year |
Month |
Budget |
1 |
North |
2014 |
June |
150 |
1 | North | 2014 | May | 200 |
2 | North | 2014 | May | 350 |
3 | South | 2013 | May | 200 |
4 | South | 2013 | May | 300 |
4 | South | 2014 | June | 500 |
解釋
已使用唯一整數值取代 KeyToOtherTable 欄位值,因此,已減少欄位值的長度,而能節省記憶體。兩個表格中的索引鍵欄位受到 AutoNumber 影響,並且表格保持連結。該範例僅供示範之用,在處理含大量列的表格時具有意義。