本章主要展示有关序表(排列)的数据维护的代码参考,比如完整复制序表、向序表插入(多条)(空)记录、从序表删除(多条)记录、 修改(多条)记录的字段值、修改指定位置的记录越界则自动补、为序表添加计算列、基于指定序表(排列)创建新序表、合并和拆分序表、将序列填入新创建的序表产生新记录、将序表(排列)的字段值取出拼成序列、将序列成员填入序表(排列)作为字段值、将序列成员竖着填入序表(排列)作为字段值、抄录序表(排列)的字段值到另一序表(排列)、修改指定字段字段值等。
|
A |
|
1 |
=demo.query("select NAME,EVENT, SCORE from GYMSCORE") |
|
2 |
=A1.derive() |
完整复制序表 |
3 |
=A1.to(,) |
仅复制成排列 |
|
A |
|
1 |
=create(ID,NAME,AGE) |
创建空序表 |
2 |
>A1.insert(0,10,"Lucy",20) |
末尾插入1记录 |
3 |
>A1.insert(1,1,"Jim",19) |
第1个位置插入1记录 |
4 |
>A1.insert(2:8,#+1,"Name"+string(#+1),rand(4)+18) |
第2个位置起插入8记录 |
5 |
=create(id,NAME,Age) |
创建空序表 |
6 |
>A5.insert(0:5,#+10,"Name"+string(#+10),rand(4)+18) |
末尾插入5记录 |
7 |
=A1.insert@r(0:A5) |
A5的记录插入A1 |
8 |
=A1.insert@f(0:A5) |
A5的同名字段插入A1 |
9 |
>A1.insert(2) |
在位置2前插入1条空记录 |
10 |
>A1.insert(0:10,~:ID) |
最后追加10条记录,并设置"ID"字段值 |
|
A |
|
1 |
=demo.query("select NAME, EVENT, SCORE from GYMSCORE") |
|
2 |
>A1.delete(2) |
删除第2条记录 |
3 |
>A1.delete([4,6,1]) |
删除多条记录 |
4 |
>A1.delete(A1.select(SCORE<15)) |
删除指定条件的记录 |
|
A |
|
1 |
=demo.query("select NAME,EVENT, SCORE from GYMSCORE") |
|
2 |
>A1.run(SCORE+2:SCORE) |
修改全部记录 |
3 |
>A1.select(EVENT=="Vault").run(SCORE+2:SCORE) |
修改部分记录 |
|
A |
|
1 |
=demo.query("select NAME,EVENT, SCORE from GYMSCORE") |
序表 |
2 |
=A1.modify(5,"":EVENT,15:SCORE) |
修改第5条记录,越界将自动补 |
|
A |
|
1 |
=demo.query("select NAME,UNITPRICE, QUANTITY from RECEIPT") |
|
2 |
=A1.derive(UNITPRICE*QUANTITY:Amount) |
增加"Amount"字段 |
|
A |
|
1 |
=demo.query("select NAME, ABBR, CAPITAL,POPULATION from STATES") |
|
2 |
=A1.new(NAME, ABBR) |
基于原序表产生新序表 |
3 |
=A1.new(NAME:State, ABBR,CAPITAL:Capital) |
改变字段名 |
|
A |
|
1 |
=demo.query("select * from STUDENTS1") |
|
2 |
=demo.query("select * from STUDENTS2 ") |
|
3 |
=A1|A2 |
合并序表A1和A2 |
|
A |
B |
|
1 |
1 |
Tom |
|
2 |
2 |
Jack |
|
3 |
3 |
Andy |
|
4 |
=create(id,name) |
|
|
5 |
=A4.record([A1:B3]) |
|
|
|
A |
B |
|
1 |
1 |
Tom |
|
2 |
2 |
Jack |
|
3 |
3 |
Andy |
|
4 |
=create(id,name) |
|
|
5 |
=A4.record([A1:B3]) |
|
|
6 |
=A5.field(2) |
|
返回与[B1:B3]相同的序列 |
|
A |
B |
|
1 |
1 |
Tom |
|
2 |
2 |
Jack |
|
3 |
3 |
Andy |
|
4 |
=create(id, name).insert(1:3) |
|
|
5 |
=A4.paste@a([A1:B3]) |
|
|
|
A |
B |
C |
|
1 |
1 |
2 |
3 |
|
2 |
Tom |
Jack |
Andy |
|
3 |
=create(id, name).insert(1:3) |
|
|
|
4 |
=A3.modify(1:[A1:C1],~:#1) |
|
|
第一列 |
5 |
=A3.modify(1:[A2:C2],~:#2) |
|
|
第二列 |
|
A |
|
1 |
=create(ordernumber, ordervalue).insert(0:10) |
|
2 |
=demo.query("select NAME,UNITPRICE, QUANTITY from RECEIPT") |
|
3 |
=A1.paste(A2) |
|
|
A |
|
1 |
=demo.query("select * from EMPLOYEE") |
|
2 |
=A1.field("SALARY",[8000,9000]) |
修改SALARY字段,前两条记录 |
3 |
=A1.field(9,[8000,9000]) |
修改第9个字段,前两条记录 |