数据库中有这样一列数是一个深度的范围表示方法如1000~1010这样的形式 我现在要做得是把这些深度范围中的最小值和最大值取出来,我现在的做法是把这个深度以~为界拆成两列 然后取钱一列的最小值和后一列的最大值 ,这样就改变了数据库的格式,我想以~为界把数全部取出来放到一个数组里面然后取最大值和最小值  请问这样的程序如何写 指点一下 

解决方案 »

  1.   

    select max(sd),min(sd)
    from table
      

  2.   

    随手写一个,没有测试的,自已调试吧:var
    i:integer;
    itm:TStringList;
    str:string;
    begin  with adoquery1 do begin
      First;
      itm:=TStringList.Create; 
      while not eof do begin
       str:=字段值;
       itm.add(copy(str,1,pos('~',str)-1));
       itm.add(copy(str,pos('~',str),maxint)); 
       next;
       itm.Sort;
       {itm.strings[0]----------最小值}
       {itm.strings[itm.Count-1]-----------最大值}
      end;end;
    end;
      

  3.   


    var
    i:integer;
    itm:TStringList;
    str:string;
    begin  with adoquery1 do begin
      First;
      itm:=TStringList.Create; 
      while not eof do begin
       str:=字段值;
       itm.add(copy(str,1,pos('~',str)-1));
       itm.add(copy(str,pos('~',str),maxint)); 
       next;
      end;
       itm.Sort;{排序}
       {itm.strings[0]----------最小值}
       {itm.strings[itm.Count-1]-----------最大值}
    end;
    end;