举例 有 Excel 文件 Book1.xlsx,是运费标准表,部分数据如下所示: city | first1KG | add1KG | Alabama | 12 | 4 | Alaska | 12 | 4 | Arizona | 12 | 4 | Arkansas | 12 | 4 | Boston | 12 | 4 | California | 12 | 4 | Colorado | 12 | 4 | Connecticut | 12 | 4 | … | … | … |
有 Excel 文件 Book2.xlsx,是运费表,数据如下所示: oid | city | weightKG | fee | 100001 | Alaska | 15 | | 100002 | Arkansas | 13 | | 100003 | Boston | 11 | | 100004 | Montana | 3 | | 100005 | Juneau | 2.5 | | 100006 | Ohio | 8 | | 100007 | Denver | 3.6 | | 100008 | Montana | 22 | | 100009 | Nevada | 19 | |
根据运费标准表,求实际运费,结果如下: oid | city | weightKG | fee | 100001 | Alaska | 15 | 68 | 100002 | Arkansas | 13 | 60 | 100003 | Boston | 11 | 52 | 100004 | Montana | 3 | 25 | 100005 | Juneau | 2.5 | 25 | 100006 | Ohio | 8 | 40 | 100007 | Denver | 3.6 | 30 | 100008 | Montana | 22 | 120 | 100009 | Nevada | 19 | 105 |
编写 SPL 脚本: | A | 1 | =file("Book1.xlsx").xlsimport@t() | 2 | =file("Book2.xlsx").xlsimport@t() | 3 | =A2.join(city,A1:city,first1KG,add1KG) | 4 | =A3.new(oid,city,weightKG,first1KG+add1KG*(ceil(weightKG)-1):fee) | 5 | =file("result.xlsx").xlsexport@t(A4) |
A1 读取 excel 文件内容 A2 读取 excel 文件内容 A3 两表根据 city 关联 A4 求实际运费 A5 结果导出至 result.xlsx
|