FAQ > 金融建模 > 建模问题 > 数组操作

Q:如何对数组进行排名    

  • A:
    对数组排序并得到排名有以下方式:
    1)一维数组:

    r:=array(1,4,3,5,8,4);
    r1:=select thisrow as '值', thisorder as '排名' from r order by thisrow end; //正序
    //r1:=select thisrow as '值', thisorder as '排名' from r order by thisrow desc end; //逆序
    return r1;

    2)二维数组:

    stockArr:=getbkbydate('SH000300',today());
    endt:=inttodate(20120611);
    r:=array();
    for nI:=0 to length(stockArr) do
    begin
      stockid:=stockArr[nI];
      setsysparam(pn_stock(),stockid);
      r[nI]['代码']:=stockid;
      r[nI]['PE']:=stockpe(endt);
    end;
    r1:=Select * ,thisorder as '排名' from r order by ['PE'] end; //正序
    //r1:=Select * ,thisorder as '排名' from r order by ['PE'] desc end; //逆序
    return r1;