oracle    中查询最近的一天的时间  。
我的解决法案是对时间排序  , 可是我在一想要是排序的话, 那时间的分,秒都排序了  ,可我是要按天排序取最上面的一条 。 
求   :  SQL   语句  。 
跪求 。 。  。 大神指点。 

解决方案 »

  1.   

    select * from 表 where 时间 = (select max(时间) from 表 t)    ;
      

  2.   

    时间是什么格式的2012-09-04 16:16:50?是单纯对16:16:50这样的排序吗?那简单,替换掉:比较大小就行。
    查询的时候 用replace(time,':','')
      

  3.   

    那又怎么查询当天的其他列  。where 条件怎么写 。 
      

  4.   


    Select * From 表
    Where to_char(时间, 'YYYYMMDD') = '20120101'
      

  5.   

    查询       最近一天花了多少钱 ?   求  SQL    语句 。 
    表 :  table  ,列 :   money , time  时间的格式是 :  2012-09-04 16:16:50  。 
      

  6.   

    你这个时间,数据类型是字符串还是时间?如果是字符串,直接就用字符串截取就是了。如果是时间,可以用TRUNC做日期截断,也可以to_char(时间, 'YYYYMMDD')把其转为字符串进行匹配。
      

  7.   

    select sum(money) from (
    select money from table where to_char(time,'yyyymmdd') = (select to_char(max(time),'yyyymmdd') from table)
    )或者select d,m from (
    select t.*, rownum rn from (
    select to_char(time,'yyyymmdd') d,sum(money) m from table group by to_char(time,'yyyymmdd') order by to_char(time,'yyyymmdd') desc
    ) t
    ) where rn <= 1
      

  8.   

    敲的太快了,第一种写法可以
    select sum(money) from table where to_char(time,'yyyymmdd') = (select to_char(max(time),'yyyymmdd') from table)
      

  9.   


    以时间作为条件的时候,尽量不要使用 to_char   尽量用 date类型进行比较因为 字符比较使用字典序  效率不说  还有可能出现 范围不符的问题