检索与定位

阅读(2789) 标签: 检索, 定位,

本章主要展示关于检索与定位的代码参考,比如找出成员的位置、找出子序列的位置、找出满足条件的成员及其所在位置、从后向前找、找到第1个即停止/找出所有的、从第k个成员开始找、针对多个字段检索、对已经有序的序列(排列)使用二分法提高检索速度、针对检索后的结果汇总、对序表做过滤、使用主键值在排列(序表)中检索记录、找出最大值最小值所在记录和位置、找出最大值最小值所在记录和位置等。

找出成员的位置

 

A

 

1

[3,2,1,5,1]

 

2

=A1.pos(1)

3

3

=A1.pos@a(1)

[3,5]

 

找出子序列的位置

 

A

B

 

1

[1,2,3,4,5]

[4,5]

 

2

=A1.pos@c(B1)

 

4

 

找出满足条件的成员及其所在位置

 

A

 

1

=demo.query("select EID,NAME, STATE, GENDER, BIRTHDAY,HIREDATE,DEPT, SALARY from EMPLOYEE")

 

2

=A1.select(GENDER=="M")

找出所有成员

3

=A1.pselect(GENDER=="M")

找出第1个即停止,返回位置

 

从后向前找

 

A

 

1

=demo.query("select EID, NAME,STATE, GENDER, BIRTHDAY,HIREDATE,DEPT,SALARY from EMPLOYEE")

 

2

=A1.select@z(GENDER=="M")

 

3

=A1.pselect@z(GENDER=="M")

 

 

找到第一个即停止 / 找出所有的

 

A

 

1

=demo.query("select NAME,EVENT, SCORE from GYMSCORE")

 

2

=A1.pselect(EVENT:"UnevenBars")

找出一个即停止

3

=A1(A2).SCORE

某项目的成绩

4

=demo.query("select EID,NAME,STATE, GENDER,BIRTHDAY, HIREDATE,DEPT,SALARY from EMPLOYEE")

 

5

=A4.select(GENDER=="M")

找出所有的成员

6

=A4.select@1(GENDER=="M")

找出第1

7

=A4.pselect@a(GENDER=="M")

找出所有的位置

 

从第 k 个成员开始找

 

A

 

1

=demo.query("select EID,NAME,STATE,GENDER,BIRTHDAY, HIREDATE,DEPT, SALARY from EMPLOYEE")

 

2

=A1.pselect(GENDER=="M",8)

 

 

针对多个字段检索

 

A

 

1

=demo.query("select EID,NAME,STATE,GENDER,BIRTHDAY, HIREDATE, DEPT, SALARY from EMPLOYEE")

 

2

=A1.select(GENDER:"M",DEPT:"R&D")

 

3

=A1.pselect(GENDER:"M",DEPT:"R&D")

 

4

=A1.pselect@a(GENDER:"M",DEPT:"R&D")

 

 

对已经有序的序列(排列)使用二分法提高检索速度

 

A

 

1

=demo.query("select * from EMPLOYEE order by GENDER,DEPT")

 

2

=A1.select@b(GENDER:"M",DEPT:"R&D")

 

3

=A1.pselect@b(GENDER:"M",DEPT:"R&D")

 

 

针对检索后的结果汇总

 

A

 

1

=demo.query("select NAME,UNITPRICE,QUANTITY from RECEIPT")

 

2

=A1.select(NAME:"Apple").sum(UNITPRICE*QUANTITY)

 

 

对序表做过滤

 

A

 

1

=demo.query("select EID,NAME,STATE,GENDER,BIRTHDAY, HIREDATE, DEPT, SALARY from EMPLOYEE")

 

2

=A1.select(SALARY<6300)

 

3

=A1.select(SALARY>5000)

 

 

使用主键值在排列(序表)中检索记录

 

A

 

1

=demo.query("select * from SCORES")

 

2

=A1.keys(CLASS,STUDENTID)

 

3

=A1.pfind(["Class one",2])

 

4

=A1(A3)

 

5

=A1.find(["Class one",2])

 

 

找出最大值最小值所在记录和位置

 

A

 

1

=demo.query("select EID,NAME,STATE,GENDER, BIRTHDAY,HIREDATE,DEPT,SALARY from EMPLOYEE ")

 

2

=A1.sort(HIREDATE)

排序

3

=A2.pmax(BIRTHDAY)

最年轻员工所在位置

4

=A2(to(A3-1))

更早入职的员工

5

=A4.minp(BIRTHDAY).NAME

其中最年长员工的名字

 

针对选出成员计算比上期

 

A

 

1

=demo.query("select * from STOCKRECORDS")

 

2

=A1.pselect@a(CLOSING>10)

找出超过10元的交易日的位置

3

=A1.calc(A2, CLOSING/CLOSING[-1]-1)

计算相应的涨幅

4

=A2.new(A1(~).DATE:Date,A1(~).CLOSING:ClosingPrice,A3(#):Increase)

/产生结果集

TOPN 所在位置

 

A

 

1

=demo.query("select EID,NAME,STATE,GENDER, BIRTHDAY,HIREDATE,DEPT,SALARY from EMPLOYEE ")

 

2

=A1.ptop(5,BIRTHDAY)

年龄最大的5个人的位置