select  * from data a where (a.surveytime between to_date('2010-11-9 08:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2010-11-10 08:00:00','yyyy-mm-dd hh24:mi:ss')) and a.stid='50' order by surveyTime
我在查询的时候按时间排序时,有时候在同一个时间点有多条数据,所以这几条数据就无法按时间顺序来排序了。
请教   如何让查询出来的数据按存入数据库的先后顺序排序呢?

解决方案 »

  1.   

    1、oracle数据库表数据是按堆存储,是不定,也是没有顺序的。
    2、如果同一时间出现多个数据,只能再按其它字段再排序,如:order by surveyTime,other_files 如果没有其它字段是不行的。
      

  2.   

    试试:select *
      from data a
     where (a.surveytime between
           to_date('2010-11-9 08:00:00', 'yyyy-mm-dd hh24:mi:ss') and
           to_date('2010-11-10 08:00:00', 'yyyy-mm-dd hh24:mi:ss'))
       and a.stid = '50';
      

  3.   

    找到解决方法了,  其实我只要按照ID来排序就行了,ID是自增的。
    请问下, 我按ID来排序  是不是应该在ID上建立以个索引呢?(这个表没有建主键,所以ID不是主键)
    如果需要     求在ID上建立索引的代码,谢谢。
      

  4.   


    请教一下order by surveyTime,other_files  像这样是不是先按surveyTime这个排序,当同一时间有多条数据时,会自动让那几条数据以other_files  这个顺序排序吗?
      

  5.   

    1、先按surveyTime排序,surveyTime相同再按other_fileds排序,
    2、排序字段上建立索引是正确的选择。
      

  6.   

    oracle如何查询在最后时间的几条记录,表中数据没有按照时间来排序!